Top Related Projects
Documentation and issues for Pylance
An implementation of the Language Server Protocol for Python
Optional static typing for Python
A static type analyzer for Python code
Performant type-checking for python.
It's not just a linter that annoys you!
Quick Overview
Pyright is a static type checker for Python, developed by Microsoft. It's designed to be fast and highly configurable, offering both command-line functionality and integration with various code editors, including Visual Studio Code. Pyright aims to improve Python code quality and developer productivity by catching type-related errors early in the development process.
Pros
- Fast performance due to its implementation in TypeScript/JavaScript
- Highly configurable with many options to tailor type checking to specific project needs
- Supports gradual typing, allowing for incremental adoption in existing projects
- Integrates well with popular code editors, especially Visual Studio Code
Cons
- Learning curve for developers new to static typing in Python
- May require additional setup and configuration compared to some other type checkers
- Some advanced Python features or libraries might not be fully supported
- Can produce false positives in certain complex scenarios
Getting Started
To get started with Pyright:
-
Install Pyright using npm:
npm install -g pyright
-
Create a
pyrightconfig.json
file in your project root:{ "include": ["src"], "exclude": ["**/node_modules", "**/__pycache__"], "strictListInference": true, "strictDictionaryInference": true }
-
Run Pyright on your project:
pyright
For VS Code integration, install the "Pylance" extension, which includes Pyright.
To use type annotations in your Python code:
def greet(name: str) -> str:
return f"Hello, {name}!"
result: str = greet("World")
print(result)
Pyright will now check your code for type-related issues and provide feedback in your editor or command-line interface.
Competitor Comparisons
Documentation and issues for Pylance
Pros of Pylance-release
- Offers a more comprehensive language server with additional features like auto-imports and refactoring
- Provides a smoother integration with Visual Studio Code
- Includes a faster type checker optimized for VS Code
Cons of Pylance-release
- Closed-source, limiting community contributions and customizations
- Tied specifically to VS Code, reducing flexibility for other editors or IDEs
- May have a larger footprint and resource usage compared to Pyright
Code Comparison
Pyright configuration (pyrightconfig.json):
{
"include": ["src"],
"exclude": ["**/node_modules", "**/__pycache__"],
"strict": ["src"]
}
Pylance configuration (settings.json in VS Code):
{
"python.analysis.typeCheckingMode": "strict",
"python.analysis.diagnosticMode": "workspace",
"python.analysis.autoImportCompletions": true
}
Both Pyright and Pylance-release are Python static type checking tools developed by Microsoft. Pyright serves as the core engine for Pylance, which is specifically designed for VS Code integration. While Pyright is open-source and can be used independently, Pylance offers a more feature-rich experience tailored for VS Code users but with less flexibility for other environments.
An implementation of the Language Server Protocol for Python
Pros of python-language-server
- Broader language server support, including features like code completion, linting, and refactoring
- More mature project with a longer history and established user base
- Supports multiple Python versions and environments
Cons of python-language-server
- Slower performance compared to Pyright, especially for large codebases
- Less frequent updates and maintenance
- May have more dependencies and configuration requirements
Code Comparison
python-language-server:
from pyls import hookimpl
@hookimpl
def pyls_completions(document, position):
# Custom completion logic
return []
Pyright:
from pyright import LanguageServiceProvider
class CustomLanguageServiceProvider(LanguageServiceProvider):
def get_completions(self, file_path, position):
# Custom completion logic
return []
Both projects aim to provide language server functionality for Python, but they differ in their approach and focus. Pyright is specifically designed for static type checking and offers faster performance, while python-language-server provides a broader range of language server features. The choice between the two depends on specific project requirements and preferences.
Optional static typing for Python
Pros of mypy
- Longer history and more mature project, with a larger community and ecosystem
- Developed by the Python core team, ensuring close alignment with Python language features
- More extensive documentation and learning resources available
Cons of mypy
- Generally slower performance compared to Pyright
- Less comprehensive support for newer Python features and type annotations
- Can be more challenging to set up and configure for complex projects
Code Comparison
mypy:
from typing import List
def greet(names: List[str]) -> None:
for name in names:
print(f"Hello, {name}!")
Pyright:
def greet(names: list[str]) -> None:
for name in names:
print(f"Hello, {name}!")
The main difference in this example is the use of List
from the typing
module in mypy, while Pyright supports the newer Python 3.9+ syntax for type annotations using built-in types like list
.
Both tools serve similar purposes as static type checkers for Python, but they have different strengths and trade-offs. Pyright offers better performance and more up-to-date language support, while mypy has a longer history and deeper integration with the Python ecosystem. The choice between them often depends on specific project requirements and personal preferences.
A static type analyzer for Python code
Pros of pytype
- Supports gradual typing, allowing for incremental adoption in large codebases
- Performs more advanced type inference, potentially catching more errors
- Can generate stub files for third-party libraries
Cons of pytype
- Slower performance compared to Pyright
- Less comprehensive IDE integration
- May produce more false positives in some cases
Code Comparison
pytype:
def greet(name: str) -> str:
return f"Hello, {name}!"
result = greet(42) # pytype will catch this error
Pyright:
def greet(name: str) -> str:
return f"Hello, {name}!"
result = greet(42) # Pyright will also catch this error
Both tools can detect type errors in this simple example. However, pytype may provide more detailed information about the error and potential fixes in more complex scenarios.
Performant type-checking for python.
Pros of Pyre-check
- Offers incremental type checking, which can be faster for large codebases
- Provides a powerful error suppression system with
@pyre-ignore
annotations - Includes additional features like taint analysis for security auditing
Cons of Pyre-check
- Less comprehensive documentation compared to Pyright
- Smaller community and fewer third-party integrations
- May have a steeper learning curve for new users
Code Comparison
Pyright:
# @typescript-eslint/consistent-type-assertions
x = [1, 2, 3]
y = x as list[int]
Pyre-check:
# pyre-strict
x: List[int] = [1, 2, 3]
y: List[int] = x
Both tools aim to improve Python type checking, but they have different approaches. Pyright focuses on being a standalone type checker with extensive configuration options, while Pyre-check offers additional features like taint analysis. Pyright generally has more comprehensive documentation and a larger community, making it easier for newcomers to adopt. However, Pyre-check's incremental type checking can be advantageous for large projects. The code comparison shows slight differences in syntax and annotations, with Pyre-check using more explicit type declarations.
It's not just a linter that annoys you!
Pros of Pylint
- More comprehensive linting capabilities, covering a wider range of code quality and style issues
- Highly configurable with numerous options to customize checks and reporting
- Longer history and larger community, resulting in more plugins and integrations
Cons of Pylint
- Slower performance, especially on larger codebases
- Can produce more false positives, requiring additional configuration to reduce noise
- Steeper learning curve due to its extensive feature set and configuration options
Code Comparison
Pylint configuration example:
[MASTER]
ignore=CVS
ignore-patterns=
persistent=yes
load-plugins=
jobs=1
unsafe-load-any-extension=no
extension-pkg-whitelist=
Pyright configuration example:
{
"include": [
"src"
],
"exclude": [
"**/node_modules",
"**/__pycache__"
],
"strict": []
}
While both tools aim to improve Python code quality, Pylint offers more comprehensive linting with greater configurability, whereas Pyright focuses on static type checking with better performance. The choice between them depends on specific project needs and priorities.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Static Type Checker for Python
Pyright is a full-featured, standards-based static type checker for Python. It is designed for high performance and can be used with large Python source bases.
Pyright includes both a command-line tool and an extension for Visual Studio Code.
Pyright Playground
Try Pyright in your browser using the Pyright Playground.
Documentation
Refer to the documentation for installation, configuration, and usage details.
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.
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 Pyrightâs 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.
Top Related Projects
Documentation and issues for Pylance
An implementation of the Language Server Protocol for Python
Optional static typing for Python
A static type analyzer for Python code
Performant type-checking for python.
It's not just a linter that annoys you!
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot