Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function may_<trigger>() always returns false on an internal transition. #594

Closed
a-schade opened this issue Nov 8, 2022 · 4 comments
Closed
Assignees
Labels

Comments

@a-schade
Copy link

a-schade commented Nov 8, 2022

Describe the bug
A call to the may_() function returns always false on an internal transition.

Minimal working example

from transitions import Machine, State


class InactiveStateHandler:

    def __init__(self, model):
        self._model = model

    def on_enter(self) -> None:
        print("enter inactive")


class ReadyStateHandler:

    def __init__(self, model):
        self._model = model

    def on_enter(self) -> None:
        print("enter ready")


class TheMachine(Machine):

    # trigger, source, target, condition, unless, before, after, prepare
    transitions = [
        ["start", "inactive", "ready"],
        ["stop", "ready", "inactive"]
    ]

    def __init__(self):
        Machine.__init__(self, transitions=self.transitions, initial='inactive')
        self.ready_state_handler = ReadyStateHandler(self)
        self.inactive_state_handler = InactiveStateHandler(self)
        self.add_state("inactive", on_enter=self.inactive_state_handler.on_enter)
        self.add_state("ready", on_enter=self.ready_state_handler.on_enter)
        self.add_transition("start", "inactive", "ready")
        self.add_transition("stop", "ready", "inactive")
        self.add_transition("do", "ready", None, after="on_do")

    def on_do(self):
        print("Done")


m = TheMachine()
print(f"State: {m.state} Start: {m.may_start()} Stop: {m.may_stop()} Do: {m.may_do()}")
m.start()
print(f"State: {m.state} Start: {m.may_start()} Stop: {m.may_stop()} Do: {m.may_do()}")
m.dispatch("do")
@markus-work
Copy link

Thanks for solving this! 😃 When is this planned to be released?

aleneum added a commit that referenced this issue May 7, 2024
aleneum added a commit that referenced this issue May 7, 2024
@aleneum
Copy link
Member

aleneum commented May 8, 2024

Hello @markus-work,

Thanks for solving this! 😃 When is this planned to be released?

end of this week. I need to check open issues and see whether there are some major issues to be tackled. features will be postponed to the next release though.

@markus-work
Copy link

Great to hear! 😄

@aleneum
Copy link
Member

aleneum commented May 15, 2024

Hello @markus-work,

FYI: version 0.9.1 has been released

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants