Pyre: Performant type-checking for python
Presenting to you Pyre, a static type checker that has been built for Python. Pyre by flagging type errors interactively in your favourite editor is ultimately designed to help improve the quality as well as development speed in large Python codebases. It checks the annotations that are gradual type and also already a part of the Python programming language (PEP484).
The main goal for Pyre is to allow you without getting in your way to write readable, idiomatic Python:
-
Pyre is designed to be highly parallel, optimizing for near-instant responses so that its users get immediate feedback, even when the codebase is very large.
-
By design, type annotations are not required everywhere. If a user is not committed to static typing fully, or if they have an existing codebase that they gradually over time intend to convert, the user can still get useful results.
Why is Pyre Built?
At Facebook and Instagram, the use of Python is made extensively. Its features of expressiveness, flexibility, and developer productivity is what is most loved. Traditionally, when maintaining a very large product codebase that comprises millions of lines some of these benefits seem to fade. Given below are a couple of challenges:
-
The absence of static guarantees when it comes to an existing codebase can make it harder to make changes safely, therefore making the code more error-prone and actually slowing down development relative to statically typed code.
-
It is tough to build high-quality tools like navigation, autocomplete, refactoring support, and code search; lacking tools like these when working in a large codebase is especially detrimental.
To address these issues, Pyre has been built in order to be both a great platform for building deeper static analysis tools and a fast PEP 484-compliant type checker.
Pyre: The Type Checker:
Pyre is designed with keeping in mind interactive performance; the goal is to get you as soon as possible any relevant type errors. So to achieve this, it runs as a server that updates its understanding of your code in memory continually. It makes the use of Watchman to spot changes to the code. That means that Pyre is notified as soon as 'save' is hit in the user's favourite editor.
Pyre maintains a dependency graph representation of the user's code. When a change is made, the only code that has been changed will be re-analyzed by Pyre and its direct dependencies, will update along the way the dependency graph as an when needed. Results are available from the command-line, as structured JSON, or through integration with VSCode and Nuclide. Ahead of type checking, a number of features are supported by Pyre, such as with help of the Language Server Protocol (LSP) automatic re-checking of edited files.
On an internal level, Pyre's high-level architecture is similar to that of Facebook's type checker for PHP: Hack. Like the Hack type checker, Pyre is implemented in OCaml and to achieve parallelism uses a lock-free shared memory data structure.
Talking about its compatibility:
Pyre is designed for Python 3 and currently supports the majority of features that have been defined in PEP484. The aim is to make it compatible with mypy, the de facto reference implementation for Python type checking, even though there is a possibility of minor implementation differences.
Pyre, therefore, is a fast and scalable type checker meant for large python codebases, designed to by flagging type errors interactively in your editor improve code help quality and development speed and as of now follows the typing standards introduced in PEP484 and PEP526.
And as the language evolves they will continue supporting Python type checking.
For More Information: Click Here
Github: Pyre