-
-
Notifications
You must be signed in to change notification settings - Fork 96
Development Bug: pyright and other language servers cannot identify unresolved references on subclasses of StateMachine #515
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
Comments
And resolution of functions not in the subclass are correctly analyzed: from statemachine import StateMachine
def a_function_from_an_outer_scope():
return True
class MyStatemachine(StateMachine):
def __init__(self):
super().__init__()
self.this_method_does_not_exist()
this_method_also_does_not_exist()
a_function_from_an_outer_scope()
class MyNotStatemachine:
def __init__(self):
self.this_method_does_not_exist()
this_method_also_does_not_exist()
a_function_from_an_outer_scope() |
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 :( |
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. |
Hey, any idea how to solve this issue? Started using pyright recently and run into the same issue :) |
Hi @mgineer85, For this last case, you can make the linter happy by using explicit 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. |
Oh, sorry, the error is about the TransitionList I will ignore the whole file for now and might revisit this later. Thank you anyways :) |
How is the |
Definition like this
|
You can use explicit
|
Thank you! Declaring the Events explicitly fixed both of the linting errors I had:
Thank you! |
Description
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.
The text was updated successfully, but these errors were encountered: