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
Method types not inherited when overriding overloaded method #10054
Here Sub2.foo has signature def foo(self: Self@Sub2, x: int, is_str: bool -> (str | int). I would expect the same signature in the first example, however the overload obfuscates the signature.
Pyright usage: integrated into Pylance Pyright verison: 1.1.396
In general, you need to supply type annotations at each level of the hierarchy. Pyright will infer parameter types in some very specific cases — notably, where it is a simple (not polymorphic / overloaded) signature, the arity (number of parameters) and parameter names / kinds match exactly. In all other cases, you need to provide annotations in the derived class methods. This limited inference behavior was implemented to provide better language server behaviors in pylance for untyped code bases. If you're interested in type checking (i.e. you are using pyright and have type checking enabled), you should provide type annotations for your methods.
Activity
erictraut commentedon Mar 10, 2025
Pyright is working as designed here.
In general, you need to supply type annotations at each level of the hierarchy. Pyright will infer parameter types in some very specific cases — notably, where it is a simple (not polymorphic / overloaded) signature, the arity (number of parameters) and parameter names / kinds match exactly. In all other cases, you need to provide annotations in the derived class methods. This limited inference behavior was implemented to provide better language server behaviors in pylance for untyped code bases. If you're interested in type checking (i.e. you are using pyright and have type checking enabled), you should provide type annotations for your methods.