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 this code, Pyright correctly infers the type of Option(1) as Option[int], but since version 1.1.354, it incorrectly infers the type of Option.Some(2) as Option[Unknown]Pyright Playground. Prior to version 1.1.354, Pyright inferred the correct type for both cases Pyright Playground.
VS Code extension or command-line
ms-python.vscode-pylance v2024.4.1
The text was updated successfully, but these errors were encountered:
This is by design, not a bug. This behavior was previously somewhat ambiguous in the typing spec, but the recent addition of PEP 696 (which introduces TypeVar default values) clarified how this must work.
When you call a constructor of a generic class, the specialized type of the class is not yet established and can be inferred from the arguments passed to the constructor.
By contrast, when you call a class method, the specialized type of the class is already established at the time that the method is bound to the class — prior to the call. If you don't explicitly provide type argument values, they take on their default values (as explained in PEP 696). If no default is specified, it implicitly becomes Any (i.e. Unknown).
In your example above, if you want to invoke a class method Some on Option[int], you'd need to write Option[int].Some(2). Or if you use PEP 696 to specify a default type argument for T, you could do the following:
Describe the bug
Since version 1.1.354, Pyright unable to infer the type of a generic class method in certain scenarios.
Code or Screenshots
In this code, Pyright correctly infers the type of
Option(1)
asOption[int]
, but since version 1.1.354, it incorrectly infers the type ofOption.Some(2)
asOption[Unknown]
Pyright Playground. Prior to version 1.1.354, Pyright inferred the correct type for both cases Pyright Playground.VS Code extension or command-line
ms-python.vscode-pylance
v2024.4.1
The text was updated successfully, but these errors were encountered: