-
Notifications
You must be signed in to change notification settings - Fork 1.8k
--project as a directory should ignore pyproject.toml without tool.pyright #11320
Description
Feature Request
We have a monorepo setup (root pyproject.toml with [tool.pyright] with the "default" configuration all projects should inherit (unless they choose to override).
For typechecking, we run pyright "per-project-directory" using --project (to ensure the correct pyproject.toml gets loaded for that project).
This all works if the project either:
- Doesn't have a
pyproject.toml(uses root config ✅ ) - Has a
pyproject.tomland has a[tool.pyright](ideally usingextends = "../../pyproject.toml", but that's on us to enforce) ✅
However, some projects have a pyproject.toml for non-pyright reasons (specifying project metadata, configuring other tools like ruff). And for these projects, the mere existence of pyproject.toml forces pyright to load config from it, of which there is no config, and therefore we get the pyright defaults.
Example bad behavior
Given
.
├── pyproject.toml // [tool.pyright].reportUnnecessaryTypeIgnoreComment = true
├── no-pyprojecttoml
│ └── file.py // x = 1 # type: ignore
├── pyprojecttoml-with-config
│ ├── file.py // x = 1 # type: ignore
│ └── pyproject.toml // [tool.pyright].reportUnnecessaryTypeIgnoreComment = false
└── pyprojecttoml-without-config
├── file.py // x = 1 # type: ignore
└── pyproject.toml // (empty)
Then:
- `uv tool run pyright --verbose --project pyprojecttoml-without-config pyprojecttoml-without-config/file.py
- Loads root
pyproject.tomland therefore reports unnecessary type ignore ✅
- Loads root
uv tool run pyright --verbose --project pyprojecttoml-with-config pyprojecttoml-with-config/file.py- Loads project
pyproject.tomland therefore doesn't report unnecessary type ignore ✅
- Loads project
uv tool run pyright --verbose --project pyprojecttoml-without-config pyprojecttoml-without-config/file.py- Loads project
pyproject.toml(warns that ithas no "[tool.pyright]" section) and doesn't report unnecessary type ignore ❌
- Loads project
(uv tool run pyright --version gives me 1.1.408 )
Solution
After the warning about missing "[tool.pyright]" section, try and load config from the CWD (as if the project pyproject.toml didn't exist)
(FWIW ruff actually does this, so there's some precedence)