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

FysomGlobal does not honor '=' destination #40

Open
moznuy opened this issue Nov 14, 2019 · 1 comment
Open

FysomGlobal does not honor '=' destination #40

moznuy opened this issue Nov 14, 2019 · 1 comment

Comments

@moznuy
Copy link

moznuy commented Nov 14, 2019

Small snippet to illustrate:

from fysom import FysomGlobal, FysomGlobalMixin

class Model(FysomGlobalMixin, object):
    GSM = FysomGlobal(
        events=[('test', ('green', 'not_important'), '=')],
        initial='green',
        state_field='state'
    )

    def __init__(self):
        self.state = None
        super(Model, self).__init__()


obj = Model()
print(obj.current)  # 'green'
obj.test()
print(obj.current)  # '='

I tried to add 2 events with the same name:

events=[('test', 'green', 'green')],
events=[('test', 'not_important', 'not_important'],

but the latter overrides the former, which do not correspond with Fysom behaviour:

from fysom import Fysom
fsm = Fysom(
    events=[
        ('change', 'green', 'red'),
        ('test', 'green', 'green'),
        ('test', 'red', 'red')],
    initial='green')

print(fsm.current) # green
fsm.test()
print(fsm.current) # green
fsm.change()
print(fsm.current) # red
fsm.test()
print(fsm.current) # red

and

from fysom import FysomGlobal, FysomGlobalMixin, Fysom

class Model(FysomGlobalMixin, object):
    GSM = FysomGlobal(
        events=[
            ('change', 'green', 'red'),
            ('test', 'green', 'green'),
            ('test', 'red', 'red')],
        initial='green',
        state_field='state'
    )

    def __init__(self):
        self.state = None
        super(Model, self).__init__()


obj = Model()
print(obj.current)  # 'green'
obj.test()          # 'fysom.FysomError: event test inappropriate in current state green'
print(obj.current)
obj.change()
print(obj.current)
obj.test()
print(obj.current)

So now I forced to create to different events and fire them based on state which defeats the point of using FSM.

@frank-pet
Copy link

The issue isn't just related to the "=' construct. The _map structure for FysomGlobal does not permit the case in Fysom where the same event can trigger multiple destination, source pairs. moznuy's example with two events with the same name is exactly the problem I have. As he says, this is very different behavior from Fysom.

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

No branches or pull requests

2 participants