Microsoft unveils speedy type checker for Python

Pyright aims to be a faster type checker for Python than existing projects, and doesn't need Python itself

Microsoft unveils speedy type checker for Python
Getty Images
Current Job Listings

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.

Microsoft claims in the Readme for the project that Pyright is “typically 5X faster” than other Python type checkers that are themselves written in Python, such as Mypy, Pytype, and Pyre. Writing those tools in Python is convenient, but they can only run as fast as Python itself, and Python’s default runtime doesn’t emphasize performance. That said, the performance of these tools aren’t absolutes; it depends mainly on the systems they run on and the code bases they analyze.

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.