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

Development Bug: pyright and other language servers cannot identify unresolved references on subclasses of StateMachine #515

Open
comalice opened this issue Jan 14, 2025 · 3 comments

Comments

@comalice
Copy link
Contributor

  • Python State Machine version: 2.5.0
  • Python version: 3.12
  • Operating System: Windows 11

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.

from statemachine import StateMachine


class MyStatemachine(StateMachine):
    def __init__(self):
        super().__init__()
        self.this_method_does_not_exist()

class MyNotStatemachine:
    def __init__(self):
        self.this_method_does_not_exist()

image

@comalice
Copy link
Contributor Author

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()

image

@fgmacedo
Copy link
Owner

Hi @comalice , thanks for reporting this!

I think that this is the source of this issue:

if TYPE_CHECKING:
"""Makes mypy happy with dynamic created attributes"""
def __getattr__(self, attribute: str) -> Any: ...

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
Copy link
Contributor Author

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.

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