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

Problems with Machine init #545

Closed
VKSolovev opened this issue Sep 9, 2021 · 3 comments
Closed

Problems with Machine init #545

VKSolovev opened this issue Sep 9, 2021 · 3 comments
Assignees
Milestone

Comments

@VKSolovev
Copy link

Thank you for taking the time to report a bug! Your support is essential for the maintenance of this project. Please fill out the following fields to ease bug hunting and resolving this issue as soon as possible:

Impossible to init machine on model with castom implementation of eq

from transitions import Machine

class C:
    def __init__(self):
        Machine(self, states=['state'], transitions=[], initial='state')
    
    def __eq__(self, other):
        if not isinstance(other, C):
            raise NotImplemented
        return True
    
c = C()

This raises NotImplemented. The problem is in core 604

mod = self if mod == 'self' else mod

When mod is compared with the string the eq of C raises error. It can be replaces with

mod = self if mod is 'self' else mod
@aleneum
Copy link
Member

aleneum commented Sep 10, 2021

Hello @VKSolovev,

x is "a string" will raise a SyntaxWarning in Python 3.8 and it seems like this was elevated to a SyntaxError in Python 3.9 and beyond (see Dennis Sweeney's comment). Maybe there is another way to enable easier override of __eq__.

I removed the bug label since using == is intended behaviour (as of now).

aleneum added a commit that referenced this issue Sep 10, 2021
This enables identity checks to determine whether a machine should add itself as a model (#545)
@aleneum
Copy link
Member

aleneum commented Sep 10, 2021

I moved 'self' to a class variable. This may cause some minor inconvenience for users that would like to add a couple of models AND the machine itself ([mod1, mod2, Machine.self_literal]) but an identity check feels like the better approach. I pushed this change to the master branch with af7008e. Let me know if this solves your issue.

@aleneum aleneum added this to the 0.8.10 milestone Sep 27, 2021
@aleneum
Copy link
Member

aleneum commented Sep 27, 2021

I assume this issue has been solved by this commit since there has not been any feedback. Feel free to comment anyway and I will reopen the issue if necessary.

@aleneum aleneum closed this as completed Sep 27, 2021
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