Static type checker for Python
Go to file
2020-08-26 15:00:16 -07:00
.github Small improvements to documentation. 2020-08-02 14:20:07 -07:00
.vscode Revert markdown changes, restore .vscode for server (#115) 2020-02-25 12:57:54 -08:00
client Update deps, pin LSP libraries together, use Node 12.x (#971) 2020-08-26 15:00:16 -07:00
docs Changed capitalization of the python.analysis.logLevel setting so it matches Pylance. The settings code in Pyright is case insensitive, but the JSON editor emits a warning if the case doesn't match. 2020-08-20 09:17:32 -07:00
server Update deps, pin LSP libraries together, use Node 12.x (#971) 2020-08-26 15:00:16 -07:00
.eslintignore Mass reformat ts/js/md with ESLint quick fixes and prettier (#113) 2020-02-24 16:52:23 -08:00
.eslintrc.json Updated all dependencies to latest versions. The update to eslint required a small change to the .eslintrc.json config files for compatibility. 2020-06-21 09:28:53 -07:00
.gitignore added code coverage on CI. (#557) 2020-03-06 15:48:43 -08:00
.npmignore Updated build scripts to build command-line version into an npm module. 2019-03-24 02:58:01 -07:00
.prettierignore Revert markdown changes, restore .vscode for server (#115) 2020-02-25 12:57:54 -08:00
.prettierrc Upgrade to Prettier 2.0, reformat (#610) 2020-04-07 17:18:22 -07:00
CONTRIBUTING.md Updated LICENSE and CONTRIBUTING files. 2019-03-17 22:05:33 -07:00
index.debug.js Fixed index.debug.js import path, which has been broken for a long time. 2020-04-18 14:21:57 -07:00
index.js Add new entrypoint for pyright-langserver (#810) 2020-07-08 08:53:41 -07:00
langserver.index.js Add new entrypoint for pyright-langserver (#810) 2020-07-08 08:53:41 -07:00
LICENSE.txt Updated LICENSE and CONTRIBUTING files. 2019-03-17 22:05:33 -07:00
package-lock.json Update deps, pin LSP libraries together, use Node 12.x (#971) 2020-08-26 15:00:16 -07:00
package.json Update deps, pin LSP libraries together, use Node 12.x (#971) 2020-08-26 15:00:16 -07:00
README.md Add Emacs lsp-mode support in Readme (#969) 2020-08-26 12:49:23 -07:00

Pyright

Static type checker for Python

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.

Configurability

Pyright supports configuration files that provide granular control over settings. Different “execution environments” can be associated with subdirectories within a source base. Each environment can specify different module search paths, python language versions, and platform targets.

Type Checking Features

  • PEP 484 type hints including generics
  • PEP 526 syntax for variable annotations
  • PEP 544 structural subtyping
  • PEP 561 distributing and packaging type information
  • PEP 589 typed dictionaries
  • PEP 591 final qualifier
  • PEP 593 flexible variable annotations
  • PEP 604 complementary syntax for unions
  • PEP 612 parameter specification variables
  • PEP 613 explicit type aliases
  • Type inference for function return values, instance variables, class variables, and globals
  • Type guards that understand conditional code flow constructs like if/else statements

VS Code Integration

Pyright ships as both a command-line tool and a VS Code extension that provides many powerful features that help improve programming efficiency.

VS Code Language Features

The VS Code extension supports many time-saving language features including:

  • Intelligent type completion of keywords, symbols, and import names appears when editing
  • Import statements are automatically inserted when necessary for type completions
  • Signature completion tips help when filling in arguments for a call
  • Hover over symbols to provide type information and doc strings
  • Find Definitions to quickly go to the location of a symbols definition
  • Find References to find all references to a symbol within a code base
  • Rename Symbol to rename all references to a symbol within a code base
  • Find Symbols within the current document or within the entire workspace
  • View call hierarchy information — calls made within a function and places where a function is called
  • Organize Imports command for automatically ordering imports according to PEP8 rules
  • Type stub generation for third-party libraries

Built-in Type Stubs

Pyright includes a recent copy of the stdlib type stubs from 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

Pyright includes both a command-line tool and an extension for Visual Studio Code that implements the Language Server Protocol.

For rich Python editing and debugging capabilities with Visual Studio Code, be sure to also install the official Microsoft Python extension for Visual Studio Code as Pyright only provides syntax and type checking.

Installation

VS Code Extension

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.

Vim

For vim/neovim users, you can install coc-pyright, Pyright extension for coc.nvim.

Emacs

For emacs users, you can install lsp-mode that includes lsp-pyright. To activate the pyright extension follow the instructions in the docs.

Command-line

The latest version of the command-line tool can be installed with npm, which is part of node. If you don't have a recent version of node on your system, install that first from nodejs.org.

To install pyright 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

Using Pyright with VS Code Python Extension

Pyrights type-checking functionality and language features are now incorporated into a VS Code extension called Pylance, the officially supported Python Language Server from Microsoft. Pylance is designed to work with the Python extension for VS Code. In addition to Pyrights functionality, Pylance adds compatibility with several advanced features including IntelliCode for AI-assisted completions. If you are a VS Code user, we recommend that you uninstall Pyright and instead install Pylance. You will get all the benefits of Pyright and more!

Installing both Pyright and Pylance at the same time is not recommended. If both are installed and enabled, you will see duplicate errors, hover text, and completion suggestions.

Documentation

Limitations

Pyright provides support for Python 3.0 and newer. There is currently no plan to support older versions.

Community

Do you have questions about Pyright or Python type annotations in general? Post your questions in this gitter channel.

FAQ

Q: What is the difference between Pyright and Pylance?

A: Pyright is an open-source Python type checker and language server. Pylance leverages Pyrights functionality with additional features, some of which are not open-sourced.

Q: What is the long-term plan for Pyright?

A: Pyright is now an officially-supported Microsoft type checker for Python. It will continue to be developed and maintained as an open-source project under its original MIT license terms. The Pyright extension for VSCode is a reference implementation and is not guaranteed to be fully functional or maintained long-term.

Contributing

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. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.