You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Development Bug: pyright and other language servers cannot identify unresolved references on subclasses of StateMachine #515
As in the title, when StateMachine is subclassed, no unresolved references are found by pyright or similar language servers.
What I Did
In the following example code, the class without inheritance is flagged correctly as having an unresolved reference. The class with inheritance is not flagged correctly.
For this last case, you can make the linter happy by using explicit Event class when declaring an event.
For the first case, there's still no easy solution as the library uses dynamic properties of the language and the linters stuck to get it right because they don't run the code for real.
Hi! I'm a user of python-statemachine in some of my projects. I've submitted PR #545 that implements Generic[TModel] support to address this issue. The implementation adds type safety for the model attribute while maintaining full backward compatibility.
I'd appreciate any feedback on the approach!
Activity
comalice commentedon Jan 14, 2025
And resolution of functions not in the subclass are correctly analyzed:
fgmacedo commentedon Jan 16, 2025
Hi @comalice , thanks for reporting this!
I think that this is the source of this issue:
python-statemachine/statemachine/statemachine.py
Lines 118 to 121 in 9954890
It was added to make mypy stop complaining about dynamic-created state machine attributes.
We need to figure out another and better way, or I will forever be trapped between choosing which linter error is displayed :(
comalice commentedon Jan 20, 2025
I'll see if I can poke around and figure something out. There are mypy stub generators (used on peewee, for example) that might be useful here.
mgineer85 commentedon Feb 26, 2025
Hey, any idea how to solve this issue? Started using pyright recently and run into the same issue :)
mgineer85 commentedon Feb 26, 2025
Also there is a linting error about the name attribute of an event:

fgmacedo commentedon Feb 26, 2025
Hi @mgineer85,
For this last case, you can make the linter happy by using explicit
Eventclass when declaring an event.For the first case, there's still no easy solution as the library uses dynamic properties of the language and the linters stuck to get it right because they don't run the code for real.
mgineer85 commentedon Feb 26, 2025
Oh, sorry, the error is about the TransitionList
self.confirm. The event is actually fine.I will ignore the whole file for now and might revisit this later.
Thank you anyways :)
fgmacedo commentedon Feb 26, 2025
How is the
confirmdeclared?mgineer85 commentedon Feb 28, 2025
Definition like this
fgmacedo commentedon Mar 1, 2025
You can use explicit
Eventdeclaration, it wraps the transition list and makes the linter happy :)mgineer85 commentedon Mar 2, 2025
Thank you! Declaring the Events explicitly fixed both of the linting errors I had:
Thank you!
feat: Add Generic[TModel] support for type-safe model attribute
rodrigobnogueira commentedon Dec 26, 2025
Hi! I'm a user of python-statemachine in some of my projects. I've submitted PR #545 that implements Generic[TModel] support to address this issue. The implementation adds type safety for the model attribute while maintaining full backward compatibility.
I'd appreciate any feedback on the approach!
feat: add pyright support, Generic[TModel] for typed models, remove _…
feat: add pyright support, Generic[TModel], remove __getattr__ catch-…