Microsoft introduces Pyright, a static type checker for the Python language written in TypeScript, Pyright aims to be a faster type checker for Python than existing projects, and doesn’t need Python itself.
What are the type checking features Pyright brings in?
- It comes with support for PEP 484 (type hints including generics), PEP 526 (syntax for variable annotations), and PEP 544 (structural subtyping).
- It supports type inference for function return values, instance variables, class variables, and globals.
- It provides smart type constraints that can understand conditional code flow constructs like if/else statements.
Increased speed in type checkers in Python
Pyright shows 5x speed as compared to mypy and other existing type checkers written in Python. It was built keeping large source bases in mind and can perform incremental updates when files are modified.
No need for setting up a Python Environment
Since Pyright is written in TypeScript and runs within Node, you do not need to set up a Python environment or import third-party packages for installation. This proves really helpful when using the VS Code editor, which has Node as its extension runtime.
Pyright enables users to have granular control over settings. You can specify different execution environments for different subsets of a source base. For each environment, you can specify different PYTHONPATH settings, Python version, and platform target.