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
In the following example, the aliased staticmethod decorator is not recognized properly and leads Pyright to believe that C instances have an attribute x.
While searching for existing issues, I found this ticket where it is explained that the "@staticmethod and @classmethod decorators […] require significant special casing in Python static type checkers". I understand that this might be difficult to implement. I do not rely on this behavior and just found it while testing edge-cases. Feel free to close this ticket without comment if this is out of scope for Pyright.
Code or Screenshots
my_staticmethod=staticmethodclassUnrelated:
x: int|NoneclassC:
@my_staticmethoddeff(unrelated: Unrelated):
unrelated.x=1reveal_type(C().x) # Pyright reports `int` here, but this attribute does not exist
This is expected behavior. Static type checkers like pyright and mypy do not generally handle aliases to staticmethod or classmethod. These decorators need to be processed early in the analysis — during the "binder" phase — when symbol tables are being constructed. This phase occurs prior to any type evaluation, which depends on the symbol tables.
If you want your code to work with static analysis tools, you'll need to avoid aliasing staticmethod and classmethod.
Describe the bug
In the following example, the aliased
staticmethod
decorator is not recognized properly and leads Pyright to believe thatC
instances have an attributex
.While searching for existing issues, I found this ticket where it is explained that the "
@staticmethod
and@classmethod
decorators […] require significant special casing in Python static type checkers". I understand that this might be difficult to implement. I do not rely on this behavior and just found it while testing edge-cases. Feel free to close this ticket without comment if this is out of scope for Pyright.Code or Screenshots
(Open in Playground)
VS Code extension or command-line
Pyright 1.1.393
The text was updated successfully, but these errors were encountered: