Pyright for Python is a command-line wrapper that simplifies the installation and execution of Microsoft's Pyright static type checker within a Python environment. Pyright itself is a fast, standards-compliant type checker written in TypeScript and executed via Node.js. This wrapper handles the complexities of downloading and managing Node.js and the Pyright npm package, allowing Python developers to use Pyright without needing a separate Node.js installation. The project is actively maintained with frequent releases, typically aligned with upstream Pyright updates.
pip install pyrightNo compatibility data collected yet for this library.
This quickstart demonstrates how to run Pyright on a simple Python file. The `pyright` Python package primarily provides a command-line executable. Programmatic invocation within Python is typically done by calling the `pyright` command via `subprocess`.
Use `pip install pyright[nodejs]` for installation. Ensure network access for Node.js download if not already present in PATH.
Configure Pyright to explicitly use your project's virtual environment. Add a `[tool.pyright]` section to your `pyproject.toml` or create a `pyrightconfig.json` with `venvPath = "."` and `venv = ".venv"` (adjust `.venv` to your actual virtual environment directory name). Alternatively, configure pre-commit to install your dependencies into its hook environment.
Always explicitly include common exclusion paths (e.g., `node_modules`, `__pycache__`, your virtual environment directory) when providing a custom `exclude` list in your Pyright configuration.
Consult Pyright's documentation for its native support for advanced type features. For libraries with known MyPy plugins, verify Pyright's compatibility or consider workarounds like `type: ignore` comments if needed. This may be a reason to use MyPy if deeply integrated with such libraries.
Ensure `pyright` is installed via `pip install pyright` and that your virtual environment is activated. On Windows, ensure the `Scripts` directory of your Python environment is in the PATH.
Check your internet connection and proxy settings. Ensure the user has write permissions in the installation directory. You might try `pip install --no-cache-dir pyright` to force a fresh download.
Try clearing the `pyright` cache (usually in `~/.pyright` or `AppData/Local/pyright` on Windows) and reinstalling `pyright` via `pip install --force-reinstall pyright`. Ensure sufficient disk space and permissions.
Ensure the module is installed (`pip install some_module`) in the environment Pyright is checking. If using a virtual environment, verify `venvPath` and `venv` in your `pyrightconfig.json` or add the module's path to `extraPaths`.