@@ -1168,8 +1168,13 @@ def is_FSMState(S):
1168
1168
1169
1169
sage: from sage.combinat.finite_state_machine import is_FSMState, FSMState
1170
1170
sage: is_FSMState(FSMState('A'))
1171
+ doctest:warning...
1172
+ DeprecationWarning: The function is_FSMState is deprecated; use 'isinstance(..., FSMState)' instead.
1173
+ See https://github.com/sagemath/sage/issues/38032 for details.
1171
1174
True
1172
1175
"""
1176
+ from sage.misc.superseded import deprecation
1177
+ deprecation(38032, "The function is_FSMState is deprecated; use 'isinstance(..., FSMState)' instead.")
1173
1178
return isinstance(S, FSMState)
1174
1179
1175
1180
@@ -1923,7 +1928,7 @@ def __eq__(self, other):
1923
1928
sage: A == B
1924
1929
True
1925
1930
"""
1926
- if not is_FSMState (other):
1931
+ if not isinstance (other, FSMState ):
1927
1932
return False
1928
1933
return self.label() == other.label()
1929
1934
@@ -2177,8 +2182,13 @@ def is_FSMTransition(T):
2177
2182
2178
2183
sage: from sage.combinat.finite_state_machine import is_FSMTransition, FSMTransition
2179
2184
sage: is_FSMTransition(FSMTransition('A', 'B'))
2185
+ doctest:warning...
2186
+ DeprecationWarning: The function is_FSMTransition is deprecated; use 'isinstance(..., FSMTransition)' instead.
2187
+ See https://github.com/sagemath/sage/issues/38032 for details.
2180
2188
True
2181
2189
"""
2190
+ from sage.misc.superseded import deprecation
2191
+ deprecation(38032, "The function is_FSMTransition is deprecated; use 'isinstance(..., FSMTransition)' instead.")
2182
2192
return isinstance(T, FSMTransition)
2183
2193
2184
2194
@@ -2241,11 +2251,11 @@ def __init__(self, from_state, to_state,
2241
2251
sage: FSMTransition('A', 'B', 0, 1)
2242
2252
Transition from 'A' to 'B': 0|1
2243
2253
"""
2244
- if is_FSMState (from_state):
2254
+ if isinstance (from_state, FSMState ):
2245
2255
self.from_state = from_state
2246
2256
else:
2247
2257
self.from_state = FSMState(from_state)
2248
- if is_FSMState (to_state):
2258
+ if isinstance (to_state, FSMState ):
2249
2259
self.to_state = to_state
2250
2260
else:
2251
2261
self.to_state = FSMState(to_state)
@@ -2438,7 +2448,7 @@ def __eq__(self, other):
2438
2448
sage: t1 == t2
2439
2449
True
2440
2450
"""
2441
- if not is_FSMTransition (other):
2451
+ if not isinstance (other, FSMTransition ):
2442
2452
return False
2443
2453
return self.from_state == other.from_state \
2444
2454
and self.to_state == other.to_state \
@@ -2494,12 +2504,17 @@ def is_FiniteStateMachine(FSM):
2494
2504
2495
2505
sage: from sage.combinat.finite_state_machine import is_FiniteStateMachine
2496
2506
sage: is_FiniteStateMachine(FiniteStateMachine())
2507
+ doctest:warning...
2508
+ DeprecationWarning: The function is_FiniteStateMachine is deprecated; use 'isinstance(..., FiniteStateMachine)' instead.
2509
+ See https://github.com/sagemath/sage/issues/38032 for details.
2497
2510
True
2498
2511
sage: is_FiniteStateMachine(Automaton())
2499
2512
True
2500
2513
sage: is_FiniteStateMachine(Transducer())
2501
2514
True
2502
2515
"""
2516
+ from sage.misc.superseded import deprecation
2517
+ deprecation(38032, "The function is_FiniteStateMachine is deprecated; use 'isinstance(..., FiniteStateMachine)' instead.")
2503
2518
return isinstance(FSM, FiniteStateMachine)
2504
2519
2505
2520
@@ -3094,7 +3109,7 @@ def __init__(self,
3094
3109
3095
3110
self._allow_composition_ = True
3096
3111
3097
- if is_FiniteStateMachine (data):
3112
+ if isinstance (data, FiniteStateMachine ):
3098
3113
if initial_states is not None:
3099
3114
raise ValueError(
3100
3115
"initial_states cannot be specified when copying "
@@ -3163,7 +3178,7 @@ def __init__(self,
3163
3178
if isinstance(iter_transitions, Mapping):
3164
3179
for (st, transition) in iter_transitions.items():
3165
3180
self.add_state(st)
3166
- if is_FSMTransition (transition):
3181
+ if isinstance (transition, FSMTransition ):
3167
3182
self.add_transition(transition)
3168
3183
elif isinstance(transition, Mapping):
3169
3184
self.add_transition(sf, st, **transition)
@@ -3176,7 +3191,7 @@ def __init__(self,
3176
3191
if isinstance(transition, Iterable):
3177
3192
L = [sf]
3178
3193
L.extend(transition)
3179
- elif is_FSMTransition (transition):
3194
+ elif isinstance (transition, FSMTransition ):
3180
3195
L = transition
3181
3196
else:
3182
3197
L = [sf, transition]
@@ -3187,7 +3202,7 @@ def __init__(self,
3187
3202
# data is a something that is iterable,
3188
3203
# items are transitions
3189
3204
for transition in data:
3190
- if is_FSMTransition (transition):
3205
+ if isinstance (transition, FSMTransition ):
3191
3206
self.add_transition(transition)
3192
3207
elif isinstance(transition, Mapping):
3193
3208
self.add_transition(transition)
@@ -3598,7 +3613,7 @@ def __or__(self, other):
3598
3613
...
3599
3614
TypeError: Can only add finite state machine
3600
3615
"""
3601
- if is_FiniteStateMachine (other):
3616
+ if isinstance (other, FiniteStateMachine ):
3602
3617
return self.disjoint_union(other)
3603
3618
else:
3604
3619
raise TypeError("Can only add finite state machine")
@@ -3628,7 +3643,7 @@ def __and__(self, other):
3628
3643
...
3629
3644
NotImplementedError
3630
3645
"""
3631
- if is_FiniteStateMachine (other):
3646
+ if isinstance (other, FiniteStateMachine ):
3632
3647
return self.intersection(other)
3633
3648
3634
3649
def __imul__(self, other):
@@ -3879,7 +3894,7 @@ def __call__(self, *args, **kwargs):
3879
3894
"""
3880
3895
if not args:
3881
3896
raise TypeError("Called with too few arguments.")
3882
- if is_FiniteStateMachine (args[0]):
3897
+ if isinstance (args[0], FiniteStateMachine ):
3883
3898
return self.composition(*args, **kwargs)
3884
3899
if isinstance(args[0], Iterable):
3885
3900
if 'full_output' not in kwargs:
@@ -3969,7 +3984,7 @@ def __eq__(self, other):
3969
3984
sage: F == G
3970
3985
True
3971
3986
"""
3972
- if not is_FiniteStateMachine (other):
3987
+ if not isinstance (other, FiniteStateMachine ):
3973
3988
return False
3974
3989
if len(self._states_) != len(other._states_):
3975
3990
return False
@@ -4052,9 +4067,9 @@ def __contains__(self, item):
4052
4067
sage: FSMTransition('A', 'B', 0) in F
4053
4068
True
4054
4069
"""
4055
- if is_FSMState (item):
4070
+ if isinstance (item, FSMState ):
4056
4071
return self.has_state(item)
4057
- if is_FSMTransition (item):
4072
+ if isinstance (item, FSMTransition ):
4058
4073
return self.has_transition(item)
4059
4074
return False
4060
4075
@@ -5527,7 +5542,7 @@ def what(s, switch):
5527
5542
return s.label()
5528
5543
else:
5529
5544
return s
5530
- switch = is_FSMState (state)
5545
+ switch = isinstance (state, FSMState )
5531
5546
5532
5547
try:
5533
5548
return self._states_dict_[what(state, switch)]
@@ -5566,7 +5581,7 @@ def transition(self, transition):
5566
5581
sage: id(t) == id(F.transition(('A', 'B', 0)))
5567
5582
True
5568
5583
"""
5569
- if not is_FSMTransition (transition):
5584
+ if not isinstance (transition, FSMTransition ):
5570
5585
transition = FSMTransition(*transition)
5571
5586
for s in self.iter_transitions(transition.from_state):
5572
5587
if s == transition:
@@ -5625,7 +5640,7 @@ def has_transition(self, transition):
5625
5640
...
5626
5641
TypeError: Transition is not an instance of FSMTransition.
5627
5642
"""
5628
- if is_FSMTransition (transition):
5643
+ if isinstance (transition, FSMTransition ):
5629
5644
return transition in self.iter_transitions()
5630
5645
raise TypeError("Transition is not an instance of FSMTransition.")
5631
5646
@@ -6510,7 +6525,7 @@ def add_state(self, state):
6510
6525
except LookupError:
6511
6526
pass
6512
6527
# at this point we know that we have a new state
6513
- if is_FSMState (state):
6528
+ if isinstance (state, FSMState ):
6514
6529
s = state
6515
6530
else:
6516
6531
s = FSMState(state)
@@ -6610,7 +6625,7 @@ def add_transition(self, *args, **kwargs):
6610
6625
if len(args) + len(kwargs) == 1:
6611
6626
if len(args) == 1:
6612
6627
d = args[0]
6613
- if is_FSMTransition(d ):
6628
+ if isinstance(d, FSMTransition ):
6614
6629
return self._add_fsm_transition_(d)
6615
6630
else:
6616
6631
d = next(iter(kwargs.values()))
@@ -7353,8 +7368,8 @@ def concatenation(self, other):
7353
7368
....: if C(w)]
7354
7369
[[0, 1]]
7355
7370
sage: from sage.combinat.finite_state_machine import (
7356
- ....: is_Automaton, is_Transducer )
7357
- sage: is_Automaton(C )
7371
+ ....: Automaton, Transducer )
7372
+ sage: isinstance(C, Automaton )
7358
7373
True
7359
7374
7360
7375
Concatenation of two transducers::
@@ -7377,7 +7392,7 @@ def concatenation(self, other):
7377
7392
([0, 1], [1, 0]),
7378
7393
([1, 0], [2, 1]),
7379
7394
([1, 1], [2, 0])]
7380
- sage: is_Transducer(C )
7395
+ sage: isinstance(C, Transducer )
7381
7396
True
7382
7397
7383
7398
@@ -7446,10 +7461,10 @@ def concatenation(self, other):
7446
7461
TypeError: A finite state machine can only be concatenated
7447
7462
with a another finite state machine.
7448
7463
"""
7449
- if not is_FiniteStateMachine (other):
7464
+ if not isinstance (other, FiniteStateMachine ):
7450
7465
raise TypeError('A finite state machine can only be concatenated '
7451
7466
'with a another finite state machine.')
7452
- if is_Automaton (other) != is_Automaton (self):
7467
+ if isinstance (other, Automaton ) != isinstance (self, Automaton ):
7453
7468
raise TypeError('Cannot concatenate finite state machines of '
7454
7469
'different types.')
7455
7470
@@ -7532,7 +7547,7 @@ def kleene_star(self):
7532
7547
Transition from 1 to 2: 1|-]
7533
7548
sage: from sage.combinat.finite_state_machine import (
7534
7549
....: is_Automaton, is_Transducer)
7535
- sage: is_Automaton(B )
7550
+ sage: isinstance(B, Automaton )
7536
7551
True
7537
7552
sage: [w for w in ([], [0, 1], [0, 1, 0], [0, 1, 0, 1], [0, 1, 1, 1])
7538
7553
....: if B(w)]
@@ -7550,7 +7565,7 @@ def kleene_star(self):
7550
7565
[Transition from 0 to 1: 0|1,
7551
7566
Transition from 0 to 1: 1|0,
7552
7567
Transition from 1 to 0: -|-]
7553
- sage: is_Transducer(S )
7568
+ sage: isinstance(S, Transducer )
7554
7569
True
7555
7570
sage: for w in ([], [0], [1], [0, 0], [0, 1]):
7556
7571
....: print("{} {}".format(w, S.process(w)))
@@ -7827,10 +7842,10 @@ def default_final_function(*args):
7827
7842
if isinstance(other, Iterable):
7828
7843
machines = [self]
7829
7844
machines.extend(other)
7830
- if not all(is_FiniteStateMachine(m ) for m in machines):
7845
+ if not all(isinstance(m, FiniteStateMachine ) for m in machines):
7831
7846
raise ValueError("other must be a finite state machine "
7832
7847
"or a list of finite state machines.")
7833
- elif is_FiniteStateMachine (other):
7848
+ elif isinstance (other, FiniteStateMachine ):
7834
7849
machines = [self, other]
7835
7850
else:
7836
7851
raise ValueError("other must be a finite state machine or "
@@ -8082,9 +8097,9 @@ def composition(self, other, algorithm=None,
8082
8097
....: is_Automaton, is_Transducer)
8083
8098
sage: T = Transducer([(0, 0, 0, 0)], initial_states=[0])
8084
8099
sage: A = Automaton([(0, 0, 0)], initial_states=[0])
8085
- sage: is_Transducer (T.composition(T, algorithm='direct'))
8100
+ sage: isinstance (T.composition(T, algorithm='direct'), Transducer )
8086
8101
True
8087
- sage: is_Transducer (T.composition(T, algorithm='explorative'))
8102
+ sage: isinstance (T.composition(T, algorithm='explorative'), Transducer )
8088
8103
True
8089
8104
sage: T.composition(A, algorithm='direct')
8090
8105
Traceback (most recent call last):
@@ -8102,9 +8117,9 @@ def composition(self, other, algorithm=None,
8102
8117
Traceback (most recent call last):
8103
8118
...
8104
8119
TypeError: Composition with automaton is not possible.
8105
- sage: is_Automaton (A.composition(T, algorithm='direct'))
8120
+ sage: isinstance (A.composition(T, algorithm='direct'), Automaton )
8106
8121
True
8107
- sage: is_Automaton (A.composition(T, algorithm='explorative'))
8122
+ sage: isinstance (A.composition(T, algorithm='explorative'), Automaton )
8108
8123
True
8109
8124
8110
8125
Non-deterministic final output cannot be handled::
@@ -10926,12 +10941,20 @@ def is_Automaton(FSM):
10926
10941
10927
10942
sage: from sage.combinat.finite_state_machine import is_FiniteStateMachine, is_Automaton
10928
10943
sage: is_Automaton(FiniteStateMachine())
10944
+ doctest:warning...
10945
+ DeprecationWarning: The function is_Automaton is deprecated; use 'isinstance(..., Automaton)' instead.
10946
+ See https://github.com/sagemath/sage/issues/38032 for details.
10929
10947
False
10930
10948
sage: is_Automaton(Automaton())
10931
10949
True
10932
10950
sage: is_FiniteStateMachine(Automaton())
10951
+ doctest:warning...
10952
+ DeprecationWarning: The function is_FiniteStateMachine is deprecated; use 'isinstance(..., FiniteStateMachine)' instead.
10953
+ See https://github.com/sagemath/sage/issues/38032 for details.
10933
10954
True
10934
10955
"""
10956
+ from sage.misc.superseded import deprecation
10957
+ deprecation(38032, "The function is_Automaton is deprecated; use 'isinstance(..., Automaton)' instead.")
10935
10958
return isinstance(FSM, Automaton)
10936
10959
10937
10960
@@ -11145,7 +11168,7 @@ def intersection(self, other, only_accessible_components=True):
11145
11168
sage: a1.remove_epsilon_transitions() # not tested (since not implemented yet)
11146
11169
sage: a1.intersection(a2) # not tested
11147
11170
"""
11148
- if not is_Automaton (other):
11171
+ if not isinstance (other, Automaton ):
11149
11172
raise TypeError(
11150
11173
"Only an automaton can be intersected with an automaton.")
11151
11174
@@ -12131,12 +12154,20 @@ def is_Transducer(FSM):
12131
12154
12132
12155
sage: from sage.combinat.finite_state_machine import is_FiniteStateMachine, is_Transducer
12133
12156
sage: is_Transducer(FiniteStateMachine())
12157
+ doctest:warning...
12158
+ DeprecationWarning: The function is_Transducer is deprecated; use 'isinstance(..., Transducer)' instead.
12159
+ See https://github.com/sagemath/sage/issues/38032 for details.
12134
12160
False
12135
12161
sage: is_Transducer(Transducer())
12136
12162
True
12137
12163
sage: is_FiniteStateMachine(Transducer())
12164
+ doctest:warning...
12165
+ DeprecationWarning: The function is_FiniteStateMachine is deprecated; use 'isinstance(..., FiniteStateMachine)' instead.
12166
+ See https://github.com/sagemath/sage/issues/38032 for details.
12138
12167
True
12139
12168
"""
12169
+ from sage.misc.superseded import deprecation
12170
+ deprecation(38032, "The function is_Transducer is deprecated; use 'isinstance(..., Transducer)' instead.")
12140
12171
return isinstance(FSM, Transducer)
12141
12172
12142
12173
@@ -12345,7 +12376,7 @@ def intersection(self, other, only_accessible_components=True):
12345
12376
Transducers*, chapter in *Handbook of Finite State Based Models and
12346
12377
Applications*, edited by Jiacun Wang, Chapman and Hall/CRC, 2012.
12347
12378
"""
12348
- if not is_Transducer (other):
12379
+ if not isinstance (other, Transducer ):
12349
12380
raise TypeError(
12350
12381
"Only a transducer can be intersected with a transducer.")
12351
12382
@@ -13874,8 +13905,13 @@ def is_FSMProcessIterator(PI):
13874
13905
13875
13906
sage: from sage.combinat.finite_state_machine import is_FSMProcessIterator, FSMProcessIterator
13876
13907
sage: is_FSMProcessIterator(FSMProcessIterator(FiniteStateMachine([[0, 0, 0, 0]], initial_states=[0]), []))
13908
+ doctest:warning...
13909
+ DeprecationWarning: The function is_FSMProcessIterator is deprecated; use 'isinstance(..., FSMProcessIterator)' instead.
13910
+ See https://github.com/sagemath/sage/issues/38032 for details.
13877
13911
True
13878
13912
"""
13913
+ from sage.misc.superseded import deprecation
13914
+ deprecation(38032, "The function is_FSMProcessIterator is deprecated; use 'isinstance(..., FSMProcessIterator)' instead.")
13879
13915
return isinstance(PI, FSMProcessIterator)
13880
13916
13881
13917
0 commit comments