pyright/README.md

113 lines
7.2 KiB
Markdown
Raw Normal View History

2019-03-12 07:33:50 +03:00
![Pyright](/docs/img/PyrightLarge.png)
2019-03-12 07:30:44 +03:00
# Static type checker for Python
2019-03-12 07:30:44 +03:00
### Speed
Pyright is a fast type checker meant for large Python source bases. It can run in a “watch” mode and performs fast incremental updates when files are modified.
2019-03-12 07:30:44 +03:00
2019-03-12 08:02:23 +03:00
### No Dependency on Python Environment
Pyright does not require a Python environment or imported third-party packages to be installed.
2019-03-12 07:30:44 +03:00
### Configurability
Pyright supports [configuration files](/docs/configuration.md) that provide granular control over settings. Different “execution environments” can be associated subdirectories within a source base. Each environment can specify different module search paths, python language versions, and platform targets.
2019-03-12 07:30:44 +03:00
### Type Checking Features
Pyright supports:
2019-03-21 09:27:25 +03:00
* [PEP 484](https://www.python.org/dev/peps/pep-0484/) type hints including generics
2019-03-12 07:30:44 +03:00
* [PEP 526](https://www.python.org/dev/peps/pep-0526/) syntax for variable annotations
* [PEP 544](https://www.python.org/dev/peps/pep-0544/) structural subtyping
* Type inference for function return values, instance variables, class variables, and globals
2019-03-21 09:27:25 +03:00
* Smart type constraints that understand conditional code flow constructs like if/else statements
2019-03-12 07:30:44 +03:00
### Built-in Type Stubs
Pyright includes a recent copy of the stdlib type stubs from [Typeshed](https://github.com/python/typeshed). It can be configured to use another (perhaps more recent or modified) copy of the Typeshed type stubs. Of course, it also works with custom type stub files that are part of your project.
### Command-line Tool or Visual Studio Code Extension
2019-04-08 22:06:18 +03:00
Pyright includes both a [command-line tool](/docs/command-line.md) and an [extension for Visual Studio Code](https://github.com/Microsoft/pyright) that implements the [Language Server Protocol](https://microsoft.github.io/language-server-protocol/).
2019-03-12 06:38:50 +03:00
For rich Python editing and debugging cabailities with Visual Studio Code, be sure to also install the official [Microsoft Python extension for Visual Studio Code](https://marketplace.visualstudio.com/itemdetails?itemName=ms-python.python) as Pyright only provides syntax and type checking.
2019-03-12 06:45:56 +03:00
2019-03-20 22:41:01 +03:00
## Documentation
2019-04-07 01:07:20 +03:00
* [Getting Started with Type Checking](/docs/getting-started.md)
2019-03-20 22:41:01 +03:00
* [Command-line Options](/docs/command-line.md)
* [Configuration](/docs/configuration.md)
* [Import Resolution](/docs/import-resolution.md)
* [Building & Debugging](/docs/build-debug.md)
* [Pyright Internals](/docs/internals.md)
2019-03-20 22:41:01 +03:00
2019-03-20 02:07:43 +03:00
## Limitations
Pyright currently provides support for Python 3.0 and newer. There is currently no plan to support older versions.
2019-03-29 08:53:46 +03:00
Pyright is a work in progress. Type-checking capabilities are not fully implemented. For a list of incomplete functionality, refer to the TODO list below.
2019-03-20 02:07:43 +03:00
## FAQ
2019-04-08 19:48:57 +03:00
**Q:** What is the difference between pyright and the [Microsoft Python Visual Studio Code plugin](https://github.com/Microsoft/vscode-python)?
2019-03-20 02:07:43 +03:00
2019-04-08 19:48:57 +03:00
**A:** Pyright is focused entirely on type checking, and is a side project with no dedicated team. The Python VS Code plugin is Microsoft's officially supported extension for Visual Studio Code, and provides diverse array of features including auto-complete, debugging, linter plugins, type checking plugins, and much more. Pyright can be used in alongide the Microsoft Python extension to combine the rich capabilities the Python extension provides with the type checking capabilities of pyright.
2019-03-20 02:07:43 +03:00
2019-03-27 16:55:38 +03:00
**Q:** What is the difference between pyright and the [Microsoft Python Language Server](https://github.com/Microsoft/python-language-server)?
2019-03-22 07:44:58 +03:00
2019-04-08 22:06:18 +03:00
**A:** The Microsoft Python Language Server is a [language server protocol (LSP)](https://microsoft.github.io/language-server-protocol/) implementation that works with the Microsoft Python Visual Studio Code plugin, and it is officially supported by a team of Microsoft engineers. It focuses on providing core editing capabilities such as auto-completion (including 3rd party libraries), code navigation, documentation, with syntax checking and some type checking capabilities. Pyright is focused entirely on providing fast syntax and comprehensive type checking for your own code base with some unique features such as more configurabilty, command-line execution.
2019-04-08 19:48:57 +03:00
**Q:** What is the long term plan for pyright?
2019-04-08 19:48:57 +03:00
**A:** Pyright is a side project with no dedicated team, there is no guarantee of continued development on the project. If you find it useful feel free to use it and contribute to the code base.
## Installation
You can install the latest-published version of the Pyright VS Code extension directly from VS Code. Simply open the extensions panel and search for `pyright`.
2019-03-20 02:07:43 +03:00
The latest version of the command-line tool can be installed with npm. To install it globally:
`npm install -g pyright`
On MacOS or Linux, sudo is required to install globally:
`sudo npm install -g pyright`
Once installed, you can run the tool from the command line as follows:
`pyright <options>`
To update to the latest version:
`sudo npm update -g pyright`
2019-03-20 02:07:43 +03:00
2019-03-12 07:30:44 +03:00
## TODO
Pyright is a work in progress. The following functionality is not yet finished. If you would like to contribute to any of these areas, contact the maintainers of the repo.
* Validate that all abstract methods are overridden
2019-04-02 05:26:06 +03:00
* Type analysis support for generators
* Type analysis support for coroutines
* Type analysis support for async functions and lambdas
2019-03-22 21:42:30 +03:00
* Support for old-style type annotations within comments
2019-03-17 19:31:42 +03:00
* Address the many TODO comments in the code
* Provide switch that treats instance variables and methods that begin with underscore as private
2019-03-20 07:03:50 +03:00
* Validate parameters for magic functions
* Synthesize TypeVar param and return types for lambdas where possible
2019-03-12 07:30:44 +03:00
* Validate that overridden methods in subclass have same signature as base class methods
* Verify that exception classes inherit from base Exception
2019-03-31 02:37:15 +03:00
* Add support for inference of subclass type vars based on method parameter types declared in subclass
* Validate consistency of subclass type vars across all declared methods
* Add support for type hints on var-arg parameters
* Add support for NoReturn type
* Flag assignments to read-only values (`None`, `True`, `False`, `__debug__`) as errors
2019-03-22 21:42:30 +03:00
* Revamp support for properties - model with Descriptor protocol, detect missing setter
2019-03-20 07:03:50 +03:00
* Add numeric codes to diagnostics and a configuration mechanism for disabling errors by code
2019-03-12 07:30:44 +03:00
2019-03-12 06:45:56 +03:00
## Contributing
2019-03-12 06:38:50 +03:00
This project welcomes contributions and suggestions. Most contributions require you to agree to a
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
the rights to use your contribution. For details, visit https://cla.microsoft.com.
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide
a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions
provided by the bot. You will only need to do this once across all repos using our CLA.
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.