Skip to content

Commit 412b97a

Browse files
committed
remove fastcore import, update pyright config
1 parent add62b6 commit 412b97a

File tree

7 files changed

+23
-49
lines changed

7 files changed

+23
-49
lines changed

pyformlang/finite_automaton/deterministic_finite_automaton.py

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,13 @@ def remove_start_state(self, state: Hashable) -> int:
139139
return 1
140140
return 0
141141

142+
def get_next_state(self, s_from: Hashable, symb_by: Hashable) \
143+
-> Optional[State]:
144+
""" Make a call of deterministic transition function """
145+
s_from = to_state(s_from)
146+
symb_by = to_symbol(symb_by)
147+
return self._transition_function.get_next_state(s_from, symb_by)
148+
142149
def accepts(self, word: Iterable[Hashable]) -> bool:
143150
""" Checks whether the dfa accepts a given word
144151
@@ -168,8 +175,7 @@ def accepts(self, word: Iterable[Hashable]) -> bool:
168175
for symbol in word:
169176
if current_state is None:
170177
return False
171-
current_state = self._transition_function.get_next_state(
172-
current_state, symbol)
178+
current_state = self.get_next_state(current_state, symbol)
173179
return current_state is not None and self.is_final_state(current_state)
174180

175181
def is_deterministic(self) -> bool:
@@ -213,19 +219,12 @@ def copy(self) -> "DeterministicFiniteAutomaton":
213219
"""
214220
return self._copy_to(DeterministicFiniteAutomaton())
215221

216-
def get_next_state(self, s_from: Hashable, symb_by: Hashable) \
217-
-> Optional[State]:
218-
""" Make a call of deterministic transition function """
219-
s_from = to_state(s_from)
220-
symb_by = to_symbol(symb_by)
221-
return self._transition_function.get_next_state(s_from, symb_by)
222-
223222
def _get_previous_transitions(self) -> PreviousTransitions:
224223
previous_transitions = PreviousTransitions(self._states,
225224
self._input_symbols)
226225
for state in self._states:
227226
for symbol in self._input_symbols:
228-
next0 = self._transition_function.get_next_state(state, symbol)
227+
next0 = self.get_next_state(state, symbol)
229228
previous_transitions.add(next0, symbol, state)
230229
return previous_transitions
231230

@@ -276,8 +275,7 @@ def minimize(self) -> "DeterministicFiniteAutomaton":
276275
done = set()
277276
new_state = to_new_states[state]
278277
for symbol in self._input_symbols:
279-
next_node = self._transition_function.get_next_state(
280-
state, symbol)
278+
next_node = self.get_next_state(state, symbol)
281279
if next_node and next_node in states:
282280
next_node = to_new_states[next_node]
283281
if (next_node, symbol) not in done:
@@ -431,10 +429,8 @@ def _is_equivalent_to_minimal(
431429
matches = {self_minimal.start_state: other_minimal.start_state}
432430
while to_process:
433431
current_self, current_other = to_process.pop()
434-
if (self_minimal.is_final_state(current_self)
435-
and not other_minimal.is_final_state(current_other)) or \
436-
(not self_minimal.is_final_state(current_self)
437-
and other_minimal.is_final_state(current_other)):
432+
if self_minimal.is_final_state(current_self) != \
433+
other_minimal.is_final_state(current_other):
438434
return False
439435
next_self = list(self_minimal.get_transitions_from(current_self))
440436
next_other = list(other_minimal.get_transitions_from(current_other))

pyformlang/finite_automaton/finite_automaton.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from collections import deque
99
from networkx import MultiDiGraph
1010
from networkx.drawing.nx_pydot import write_dot
11-
from fastcore.dispatch import typedispatch
1211

1312
from pyformlang.fst import FST
1413

@@ -321,16 +320,6 @@ def remove_final_state(self, state: Hashable) -> int:
321320
return 1
322321
return 0
323322

324-
@typedispatch
325-
def __call__(self, s_from: Hashable) -> Iterable[Tuple[Symbol, Set[State]]]:
326-
"""
327-
Gives FA transitions from given state.
328-
Calls the transition function
329-
"""
330-
s_from = to_state(s_from)
331-
return self._transition_function(s_from)
332-
333-
@typedispatch
334323
def __call__(self, s_from: Hashable, symb_by: Hashable) -> Set[State]:
335324
""" Gives the states obtained after calling a symbol on a state
336325
Calls the transition function

pyformlang/finite_automaton/nondeterministic_transition_function.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
from typing import Dict, Set, Iterable, Tuple
88
from copy import deepcopy
9-
from fastcore.dispatch import typedispatch
109

1110
from .transition_function import TransitionFunction
1211
from ..objects.finite_automaton_objects import State, Symbol
@@ -128,13 +127,6 @@ def get_number_transitions(self) -> int:
128127
counter += len(s_to)
129128
return counter
130129

131-
@typedispatch
132-
def __call__(self, s_from: State) -> Iterable[Tuple[Symbol, Set[State]]]:
133-
""" Calls the transition function as a real function """
134-
if s_from in self._transitions:
135-
yield from self._transitions[s_from].items()
136-
137-
@typedispatch
138130
def __call__(self, s_from: State, symb_by: Symbol) -> Set[State]:
139131
""" Calls the transition function as a real function
140132

pyformlang/finite_automaton/tests/test_epsilon_nfa.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,8 +484,18 @@ def test_len(self):
484484
assert len(enfa) == 1
485485

486486
def test_call(self):
487+
""" Tests the call of the transition function of the ENFA """
487488
enfa = get_enfa_example1()
488-
assert len(list(enfa(2))) == 1
489+
assert enfa(2, "c") == {3}
490+
assert not enfa(3, "a")
491+
assert not enfa(2313, "qwe")
492+
493+
def test_get_transitions_from(self):
494+
""" Tests the transition obtaining from the given state """
495+
enfa = get_enfa_example1()
496+
assert list(enfa.get_transitions_from(2)) == [("c", 3)]
497+
assert not list(enfa.get_transitions_from(3))
498+
assert not list(enfa.get_transitions_from(4210))
489499

490500
def test_remove_epsilon_transitions(self):
491501
enfa = EpsilonNFA()

pyformlang/finite_automaton/transition_function.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
from typing import Dict, Set, Tuple, Iterable, Iterator
88
from abc import abstractmethod
9-
from fastcore.dispatch import typedispatch
109

1110
from ..objects.finite_automaton_objects import State, Symbol
1211

@@ -38,16 +37,6 @@ def get_number_transitions(self) -> int:
3837
def __len__(self) -> int:
3938
return self.get_number_transitions()
4039

41-
@typedispatch
42-
@abstractmethod
43-
def __call__(self, s_from: State) -> Iterable[Tuple[Symbol, Set[State]]]:
44-
"""
45-
Calls the transition function
46-
as a real function for given state.
47-
"""
48-
raise NotImplementedError
49-
50-
@typedispatch
5140
@abstractmethod
5241
def __call__(self, s_from: State, symb_by: Symbol) -> Set[State]:
5342
"""

pyrightconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,4 @@
1919
"strictParameterNoneValue": false,
2020

2121
"reportMissingParameterType": "warning",
22-
"reportRedeclaration": "none",
2322
}

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ numpy
1111
pylint
1212
pycodestyle
1313
pydot
14-
fastcore
1514
pygments>=2.7.4 # not directly required, pinned by Snyk to avoid a vulnerability
1615
pylint>=2.7.0 # not directly required, pinned by Snyk to avoid a vulnerability
1716
sphinx>=3.0.4 # not directly required, pinned by Snyk to avoid a vulnerability

0 commit comments

Comments
 (0)