Static type checker for Python
Go to file
2022-03-29 13:16:12 -06:00
.github Push from Pylance (#3064) 2022-02-16 13:29:29 -08:00
.vscode Fix more unresolvable import completions, module refactoring updates, remove getDeclaredTypeForExpression (#2369) 2021-10-04 11:25:25 -07:00
build dependency updates, bug fix on file open/close, update on getPythonVersion (#2556) 2021-11-10 12:41:56 -08:00
docs Another attempt at formatting 2022-03-20 14:35:38 -06:00
packages Fixed false positive error in "unreachable exception" detection code when the exception was typed as Type[Exception]. 2022-03-29 13:16:12 -06:00
specs Update dataclass_transforms.md (#2820) 2022-01-05 22:45:59 -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 dependency updates, bug fix on file open/close, update on getPythonVersion (#2556) 2021-11-10 12:41:56 -08:00
.gitattributes Convert repo into a lerna monorepo, add a validation workflow (#978) 2020-08-28 19:46:48 -07:00
.gitignore document highlight fixes, dict completions improvements for non string literals (#2084) 2021-07-14 13:14:42 -07:00
.prettierignore Convert repo into a lerna monorepo, add a validation workflow (#978) 2020-08-28 19:46:48 -07: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
lerna.json Published 1.1.233 2022-03-27 10:41:42 -06:00
LICENSE.txt Updated LICENSE and CONTRIBUTING files. 2019-03-17 22:05:33 -07:00
package-lock.json Updated hashes for minimist 2022-03-23 15:20:57 -06:00
package.json Pull from pylance (#3015) 2022-02-09 10:58:28 -08:00
README.md Removed provisional support for PEP 677 (Alternate Call Syntax) because the proposal was rejected by the Python steering council. 2022-02-16 22:19:39 -08:00
tsconfig.json Enabled "noImplicitOverride" compiler flag and added missing "override" keywords. 2021-06-15 17:27:16 -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 487 simpler customization of class creation
  • PEP 526 syntax for variable annotations
  • PEP 544 structural subtyping
  • PEP 561 distributing and packaging type information
  • PEP 563 postponed evaluation of annotations
  • PEP 570 position-only parameters
  • PEP 585 type hinting generics in standard collections
  • PEP 586 literal types
  • 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
  • PEP 635 structural pattern matching
  • PEP 646 variadic generics
  • PEP 647 user-defined type guards
  • PEP 655 required typed dictionary items
  • PEP 673 Self type
  • PEP 675 arbitrary literal strings
  • PEP 681 dataclass transform
  • 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

For most VS Code users, we recommend using the Pylance extension rather than Pyright. Pylance incorporates the Pyright type checker but features additional capabilities such as IntelliCode and semantic token highlighting. You can install the latest-published version of the Pylance VS Code extension directly from VS Code. Simply open the extensions panel and search for “Pylance”.

Vim

Vim/neovim users can install coc-pyright, the Pyright extension for coc.nvim.

Alternatively, ALE will automatically check your code with Pyright, without requiring any additional configuration.

Sublime Text

Sublime text users can install the LSP-pyright plugin from package control.

Emacs

Emacs users can install lsp-mode that includes lsp-pyright. To activate the pyright extension follow the instructions in the docs.

Command-line

A community-maintained Python package by the name of “pyright” is available on pypi and conda-forge. This package will automatically install node (which Pyright requires) and keep Pyright up to date.

pip install pyright

or

conda install pyright

Once installed, you can run the tool from the command line as follows: pyright <options>

Alternatively, you can install the command-line version of Pyright directly from 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

To update to the latest version: sudo npm update -g pyright

Documentation

For additional information about Python static typing, refer to this community-maintained Python Type School.

Limitations

Pyright provides support for Python 3.0 and newer. There are no plans to support older versions.

Community

Do you have questions about Pyright or Python type annotations in general? Post your questions in the discussion section.

If you would like to report a bug or request an enhancement, file a new issue in either the pyright or pylance-release issue tracker. In general, core type checking functionality is associated with Pyright while language service functionality is associated with Pylance, but the same contributors monitor both repos. For best results, provide the information requested in the issue template.

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 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 VS Code is a reference implementation and is not guaranteed to be fully functional or maintained long-term.

Contributing

This project welcomes contributions and suggestions. For feature and complex bug fix contributions, it is recommended that you first discuss the proposed change with Pyrights maintainers before submitting the pull request. 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.