pytransitions / transitions

A lightweight, object-oriented finite state machine implementation in Python with many extensions
MIT License
5.49k stars 524 forks source link

Code completion for machine triggers #494

Closed LogicEnthusiast closed 3 years ago

LogicEnthusiast commented 3 years ago

Great library! What is the recommended way to deal with lack of type ahead/code completion in the IDE for "triggers"?

Given the machine like so

class States(enum.Enum):
    IDLE = 0
    LOGIN = 1 

class Fsm(Machine):
    def __init__(self):
        Machine.__init__(self, states=States, initial=States.IDLE)
        self.add_transition(trigger='start', source=States.IDLE, dest=States.LOGIN, before=self.before_LOGIN, after=self.after_LOGIN)

Using enum class for States helps to resolve the code completion for States. But for triggers, you still have to say

m= Fsm() m.start()

or

m.to_LOGIN() m.to_IDLE()

which is error prone and not easy to remember all the sates when there are many of those.

Thank you!!

aleneum commented 3 years ago

Hello @qalexma,

What is the recommended way to deal with lack of type ahead/code completion in the IDE for "triggers"?

You can add docstrings to your models that IDEs can use for code completion (see #426) or you can customize a Machine to generate docstrings for you (see #383). Considering naming, you can adjust method naming by overidding Machine._add_model_to_state (see #385).

LogicEnthusiast commented 3 years ago

thank you!!