basedpyright 1.39.8
Overview
basedpyright is a fork of pyright that provides stricter defaults, new diagnostic rules, baseline support for incremental adoption, and re-implements Pylance-exclusive features in open-source. It ships as a PyPI package (basedpyright), making it easy to install alongside Python tooling without needing Node.js.
Key differences from upstream pyright:
- Default
typeCheckingMode is "recommended" (all rules enabled as warnings/errors)
- New diagnostic rules:
reportAny, reportExplicitAny, reportInvalidCast, reportUnsafeMultipleInheritance, and more
- Baseline support — adopt strict checks incrementally without fixing all existing errors first
- Built-in GitHub Actions annotations and GitLab code quality reports
- Pylance features (Jupyter, inlay hints, semantic highlighting, import suggestions) available to all LSP clients
enableTypeIgnoreComments disabled by default; prefer # pyright: ignore[rule]
- Defaults
pythonPlatform to "All" instead of the current OS
- Auto-detects
.venv at project root as the Python environment
- Exits with code 3 on invalid configuration (pyright silently ignores bad settings)
Usage
Installation
# Via uv (recommended)
uv add --dev basedpyright
# Or globally
uv tool install basedpyright
# Via pip
pip install basedpyright
Running the CLI
# Basic type check
basedpyright
# With verbose import resolution logs
basedpyright --verbose
# JSON output (for CI parsing)
basedpyright --outputjson
# Watch mode
basedpyright --watch
# Multi-threaded (experimental)
basedpyright --threads
# Baseline: write current errors to baseline
basedpyright --writebaseline
Configuration
Place a pyrightconfig.json at the project root, or add a [tool.basedpyright] section to pyproject.toml. A config file always takes precedence over language server settings.
Minimal config:
{
"include": ["src"],
"exclude": ["**/node_modules", "**/__pycache__"]
}
See reference files for full configuration options.
Gotchas
typeCheckingMode: "recommended" is the default — unlike pyright's "basic", all diagnostic rules are enabled. Less severe rules are warnings, but failOnWarnings defaults to true, so the CLI exits non-zero on any warning. Set failOnWarnings: false if you only want hard errors to fail CI.
enableTypeIgnoreComments is disabled by default — # type: ignore comments are ignored. Use # pyright: ignore[ruleName] instead, which requires specifying the rule and is safer. If migrating from pyright, you may need to replace type: ignore comments or enable the setting.
pythonPlatform defaults to "All" — basedpyright assumes your code runs on any OS, not just the current one. This catches platform-specific type issues earlier but may surface false positives if your code is truly platform-specific. Override with "Linux", "Darwin", or "Windows" as needed.
Baseline file is auto-updated — when errors are fixed, the baseline file (.basedpyright/baseline.json) is automatically updated to remove them. In CI, baseline defaults to lock mode (never writes). Use --writebaseline to intentionally update, or --baselinemode=auto to force local behavior in CI.
Config errors exit with code 3 — typos in config keys cause a hard failure, unlike pyright which silently ignores them. This is intentional but can be surprising when migrating configs from pyright (e.g., mode → typeCheckingMode).
reportAny catches all Any usage — this new rule fires on expressions typed as Any, including explicit Any annotations that the older reportUnknown* rules miss. Use allowedUntypedLibraries to suppress for specific third-party modules.
--venvpath is discouraged — basedpyright auto-detects .venv at project root. Use --pythonpath pointing to the interpreter instead, which is more robust.
reportInvalidCast flags dict → TypedDict casts — casting a regular dict to a TypedDict triggers this rule because type checkers treat them as unrelated types. Narrow with runtime checks or use # pyright: ignore[reportInvalidCast].
strictGenericNarrowing changes isinstance narrowing — when enabled, isinstance(x, list) narrows to list[object] instead of list[Unknown]. This is more accurate but may surface new errors in code that relied on the looser behavior.
References
- 01-installation-and-setup — Installation methods, IDE configuration, language server setup
- 02-configuration — Config files, environment options, execution environments, CLI flags
- 03-diagnostic-rules — All diagnostic rules organized by category with default severities
- 04-basedpyright-specific-features — New rules, baseline, better defaults, pylance features, CI integration
- 05-type-system — Type concepts, inference, narrowing, generics, type guards
- 06-import-resolution-and-stubs — Import resolution order, type stubs, editable installs
1---2name: basedpyright-1-39-83description: Static type checking for Python via basedpyright — a fork of pyright with stricter defaults, new diagnostic rules, baseline support, pylance features in open-source, and improved CI integration. Use when the user mentions basedpyright, pyright, type checking, static analysis, type stubs, pyrightconfig, or wants to configure/resolve Python type errors.4---56# basedpyright 1.39.878## Overview910basedpyright is a fork of [pyright](https://github.com/microsoft/pyright) that provides stricter defaults, new diagnostic rules, baseline support for incremental adoption, and re-implements Pylance-exclusive features in open-source. It ships as a PyPI package (`basedpyright`), making it easy to install alongside Python tooling without needing Node.js.1112Key differences from upstream pyright:13- Default `typeCheckingMode` is `"recommended"` (all rules enabled as warnings/errors)14- New diagnostic rules: `reportAny`, `reportExplicitAny`, `reportInvalidCast`, `reportUnsafeMultipleInheritance`, and more15- Baseline support — adopt strict checks incrementally without fixing all existing errors first16- Built-in GitHub Actions annotations and GitLab code quality reports17- Pylance features (Jupyter, inlay hints, semantic highlighting, import suggestions) available to all LSP clients18- `enableTypeIgnoreComments` disabled by default; prefer `# pyright: ignore[rule]`19- Defaults `pythonPlatform` to `"All"` instead of the current OS20- Auto-detects `.venv` at project root as the Python environment21- Exits with code 3 on invalid configuration (pyright silently ignores bad settings)2223## Usage2425### Installation2627```bash28# Via uv (recommended)29uv add --dev basedpyright3031# Or globally32uv tool install basedpyright3334# Via pip35pip install basedpyright36```3738### Running the CLI3940```bash41# Basic type check42basedpyright4344# With verbose import resolution logs45basedpyright --verbose4647# JSON output (for CI parsing)48basedpyright --outputjson4950# Watch mode51basedpyright --watch5253# Multi-threaded (experimental)54basedpyright --threads5556# Baseline: write current errors to baseline57basedpyright --writebaseline58```5960### Configuration6162Place a `pyrightconfig.json` at the project root, or add a `[tool.basedpyright]` section to `pyproject.toml`. A config file always takes precedence over language server settings.6364Minimal config:65```json66{67 "include": ["src"],68 "exclude": ["**/node_modules", "**/__pycache__"]69}70```7172See reference files for full configuration options.7374## Gotchas7576- **`typeCheckingMode: "recommended"` is the default** — unlike pyright's `"basic"`, all diagnostic rules are enabled. Less severe rules are warnings, but `failOnWarnings` defaults to `true`, so the CLI exits non-zero on any warning. Set `failOnWarnings: false` if you only want hard errors to fail CI.7778- **`enableTypeIgnoreComments` is disabled by default** — `# type: ignore` comments are ignored. Use `# pyright: ignore[ruleName]` instead, which requires specifying the rule and is safer. If migrating from pyright, you may need to replace `type: ignore` comments or enable the setting.7980- **`pythonPlatform` defaults to `"All"`** — basedpyright assumes your code runs on any OS, not just the current one. This catches platform-specific type issues earlier but may surface false positives if your code is truly platform-specific. Override with `"Linux"`, `"Darwin"`, or `"Windows"` as needed.8182- **Baseline file is auto-updated** — when errors are fixed, the baseline file (`.basedpyright/baseline.json`) is automatically updated to remove them. In CI, baseline defaults to lock mode (never writes). Use `--writebaseline` to intentionally update, or `--baselinemode=auto` to force local behavior in CI.8384- **Config errors exit with code 3** — typos in config keys cause a hard failure, unlike pyright which silently ignores them. This is intentional but can be surprising when migrating configs from pyright (e.g., `mode` → `typeCheckingMode`).8586- **`reportAny` catches all `Any` usage** — this new rule fires on expressions typed as `Any`, including explicit `Any` annotations that the older `reportUnknown*` rules miss. Use `allowedUntypedLibraries` to suppress for specific third-party modules.8788- **`--venvpath` is discouraged** — basedpyright auto-detects `.venv` at project root. Use `--pythonpath` pointing to the interpreter instead, which is more robust.8990- **`reportInvalidCast` flags `dict` → `TypedDict` casts** — casting a regular `dict` to a `TypedDict` triggers this rule because type checkers treat them as unrelated types. Narrow with runtime checks or use `# pyright: ignore[reportInvalidCast]`.9192- **`strictGenericNarrowing` changes `isinstance` narrowing** — when enabled, `isinstance(x, list)` narrows to `list[object]` instead of `list[Unknown]`. This is more accurate but may surface new errors in code that relied on the looser behavior.9394## References9596- [01-installation-and-setup](references/01-installation-and-setup.md) — Installation methods, IDE configuration, language server setup97- [02-configuration](references/02-configuration.md) — Config files, environment options, execution environments, CLI flags98- [03-diagnostic-rules](references/03-diagnostic-rules.md) — All diagnostic rules organized by category with default severities99- [04-basedpyright-specific-features](references/04-basedpyright-specific-features.md) — New rules, baseline, better defaults, pylance features, CI integration100- [05-type-system](references/05-type-system.md) — Type concepts, inference, narrowing, generics, type guards101- [06-import-resolution-and-stubs](references/06-import-resolution-and-stubs.md) — Import resolution order, type stubs, editable installs