-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Issues with finite_automaton architecture #25
Comments
This should probably be in pyformlang/pyformlang/finite_automaton/finite_automaton.py Lines 497 to 544 in 4f36e28
|
Also, I think it's a good idea to rename |
We should do the same thing with |
I'm not sure we need this method if it just calls pyformlang/pyformlang/regular_expression/regex.py Lines 547 to 573 in 4f36e28
|
@Aunsiels |
I think
but maybe we can move finite automaton objects to fst module to add type annotations without adding import cycles
|
@bygu4 If you can deal with all the cyclic imports, I would greatly appreciate it! The changes you proposed make sense. |
Current design of the
finite_automaton
module contains multiple cyclic imports, and that is due to a bigger problem: confusing architecture that makes the module hard to maintain. I think inheritance is the right way to design finite automata, but we need to refactor some methods and interfaces to restore a proper hierarchy. For example,to_deterministic
abstract method is one of the causes of cyclic imports:pyformlang/pyformlang/finite_automaton/finite_automaton.py
Lines 596 to 600 in 4f36e28
And similar situation with this method:
pyformlang/pyformlang/finite_automaton/epsilon_nfa.py
Lines 254 to 281 in 4f36e28
I think the right way to handle this, is to make sure that inherited classes don't know anything about their descendants. To do this we can get rid of
to_deterministic
abstraction, and refactor it's implementations as class methods of the DFA class. And also do the same thing withremove_epsilon_transitions
. It might look like this:And similarly with
remove_epsilon_transitions
:This may require some refactoring to make sure we don't use any protected members, but it seems completely doable.
As an alternative, maybe we could try to somehow get rid of inheritance, or just leave a couple of shortcuts like in the current state of pyformlang, but neither of these seems like a good solution.
Also there there are cyclic imports between
Regex
andEpsilonNFA
so there are more things we need to rework outside offinite_automaton
module.The text was updated successfully, but these errors were encountered: