pyright is a static type checker written by Microsoft (and they have a really good verification team)
it is written in typescript but there is a python wrapper and a pre-commit hook.
There are certain cases that mypy does not check strictly while pyright does.
For example, the following code passes mypy while not in pyright
from typing_extensions import TypeVar
T = TypeVar("T")
S = TypeVar("S", default=int)
U = TypeVar("U")
def fn(x: T, y: S, z: U):
pass
(mellea) [masataro mellea]$ pyright test.py
/home/masataro/repos/LLM/mellea/test.py
/home/masataro/repos/LLM/mellea/test.py:12:5 - error: "U" cannot appear after "S" in type parameter list because it has no default type (reportGeneralTypeIssues)
/home/masataro/repos/LLM/mellea/test.py:12:11 - warning: TypeVar "T" appears only once in generic function signature
Use "object" instead (reportInvalidTypeVarUse)
/home/masataro/repos/LLM/mellea/test.py:12:22 - warning: TypeVar "U" appears only once in generic function signature
Use "object" instead (reportInvalidTypeVarUse)
1 error, 2 warnings, 0 informations
(mellea) [masataro mellea]$ mypy test.py
Success: no issues found in 1 source file
Thsi is because it makes sure that no type parameter with a default is followed by a type parameter without a default.
Type variables are applied to the defined class in the order in which they first appear in any generic base classes, thus
fn is instantiated as fn[T, S, U] where U violates this rule.
This was originally specified in PEP 696 (Type Defaults for Type Parameters) and
is now part of official spec https://typing.python.org/en/latest/spec/generics.html#type-parameter-defaults .
The annoying thing is that VSCode suggests users to enable pylance/pyright , and reports a bunch of similar errors to the user that are not detected by mypy.
pyright is a static type checker written by Microsoft (and they have a really good verification team)
it is written in typescript but there is a python wrapper and a pre-commit hook.
There are certain cases that mypy does not check strictly while pyright does.
For example, the following code passes mypy while not in pyright
Thsi is because it makes sure that no type parameter with a default is followed by a type parameter without a default.
Type variables are applied to the defined class in the order in which they first appear in any generic base classes, thus
fnis instantiated asfn[T, S, U]whereUviolates this rule.This was originally specified in PEP 696 (Type Defaults for Type Parameters) and
is now part of official spec https://typing.python.org/en/latest/spec/generics.html#type-parameter-defaults .
The annoying thing is that VSCode suggests users to enable pylance/pyright , and reports a bunch of similar errors to the user that are not detected by mypy.