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

machine.states has wrong type specification #14

Closed
dimsuz opened this issue Nov 1, 2020 · 3 comments
Closed

machine.states has wrong type specification #14

dimsuz opened this issue Nov 1, 2020 · 3 comments

Comments

@dimsuz
Copy link

dimsuz commented Nov 1, 2020

It seems that I've found some inconsistency.

In machine.py there's a type specification:

https://github.com/davidkpiano/xstate-python/blob/ad8f8979971411a14230ec375f4bd844b5c1f126/xstate/machine.py#L8-L14

You can see that state: List[State]. But then it is initialized like so:

self.states = self.root.states # root is a StateNode

Which, as we can see in state_node.py is a Dict[str, StateNode] and not a list of State:

https://github.com/davidkpiano/xstate-python/blob/ad8f8979971411a14230ec375f4bd844b5c1f126/xstate/state_node.py#L24

Looks like typing is off somewhere.
Or did I get something wrong here? I'm not a python programmer might not know something. Also I'm not sure why no error was produced by the typechecker.

@davidkpiano
Copy link
Member

Thanks for noticing this. The typing is wrong.

davidkpiano added a commit that referenced this issue Nov 1, 2020
@dimsuz
Copy link
Author

dimsuz commented Nov 1, 2020

Hmm. It looks like this is still not right :)

If you look into state_node.py then you'll find that root.states is actually a Dict[str, StateNode], but machine assigns it directly to List[StateNode]:

# self.states :: List[StateNode], root.states :: Dict[str, StateNode]
 self.states = self.root.states

Looks like only dict values are needed here. (or machine should have 'Dict' too)

@davidkpiano
Copy link
Member

Yep, I changed it to Dict[str, StateNode]

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