BasedPyright is a static type checker for Python, forked from Pyright. It aims to provide various type checking improvements, integrate Pylance features (previously exclusive to VS Code), and introduce new diagnostic rules. Unlike upstream Pyright, it is officially published on PyPI, removing the requirement for Node.js. It is actively maintained with frequent releases, currently at version 1.39.0.
pip install basedpyrightNo compatibility data collected yet for this library.
To get started, create a Python file and a `pyproject.toml` configuration. Then run `basedpyright` from your terminal. BasedPyright will analyze your code based on the rules specified in the configuration.
Consolidate your configuration into a single file, preferably `pyproject.toml` under the `[tool.basedpyright]` section, or ensure `pyrightconfig.json` is the sole source of truth.
Add these settings to your `.vscode/settings.json`:
```json
{
"python.analysis.typeCheckingMode": "off",
"basedpyright.disableLanguageServices": true,
"python.languageServer": "None"
}
```Update your configuration to use the `hint` category for these rules, e.g., `reportUnreachable = 'hint'`.
Replace `type: ignore` with `pyright: ignore [ErrorCode]` where `[ErrorCode]` is the specific diagnostic rule you want to ignore.
Ensure your `pyproject.toml` or `pyrightconfig.json` adheres strictly to the documented schema. BasedPyright will report the specific configuration error.
Enable and configure `reportUnreachable` in your `pyproject.toml` to catch these cases, or explicitly specify target `pythonVersion` and `pythonPlatform` in your config if the code is intended for specific environments.
Ensure the module is installed in your Python environment. For project-specific imports, add the relevant paths to `extraPaths` in your `pyrightconfig.json` (e.g., `"extraPaths": ["src"]`), or restart your language server if using tools like `uv` workspaces.
Install the necessary `python3-venv` package on your system (e.g., `sudo apt install python3.12-venv` for Python 3.12 on Debian/Ubuntu-based systems).
BasedPyright generally relaxes this specific error if the type variable is only in the return position and can safely return that type at runtime. If still encountered, consider if the `TypeVar` truly needs to be generic, or if a more specific type (like `Any` or `object`) can be used if no input argument constrains the `TypeVar`.
Review your `pyrightconfig.json` or `pyproject.toml` for typos in configuration keys. Consult the official BasedPyright documentation for valid configuration options and ensure they match your installed version. BasedPyright intentionally exits with an error on invalid configuration to prevent silent misbehavior.