Microsoft has unveiled Pyright, an open source static-type-checking system for Python that aims to be faster than existing type-checking solutions for Python such as Mypy.
Written in TypeScript and running on Node.js, Pyright doesn’t require an existing Python runtime. It is chiefly designed to be used as a Visual Studio Code plugin, but can also run as a standalone command-line tool.
Pyright supports all the major type hinting and type-related syntax currently available in Python—type hints, variable notation syntax, and structural subtyping. It also supports type inference in many circumstances. The project relies on Python’s own type stub information to perform its analyses, so it can be kept in sync with Python itself even thought it isn’t written in the language.
When run as a Visual Studio Code plugin, it offers live feedback on code—type information displayed with tooltips, symbol defintiion links, and so on. Some of what Pyright offers in this regard overlaps slightly with Microsoft’s Python Language Server offering, but Pyright’s main focus is type checking and not other code linting features.
The project is still considered a work in progress, with many features listed as unfinished or to-do, such as type inference for generators or validation for
async/await declarations. One feature explicitly not planned is support for Python 2; Microsoft doesn’t intended to offer it. By contrast, Mypy, and many other code-linting and type-checking tools for Python, do offer it.
Type-checking systems for Python are mainly for the sake of ensuring a program’s correctness at runtime, not for speeding up Python applications. However, a few projects do exist that try to compile type-annotated Python to a more performant language. Mypyc, for example, compiles type-annotated Python to C. Pyright could in time be used as the foundation for a similar project.