Skip to content

--project as a directory should ignore pyproject.toml without tool.pyright #11320

@thejcannon

Description

@thejcannon

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.toml and has a [tool.pyright] (ideally using extends = "../../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.toml and therefore reports unnecessary type ignore ✅
  • uv tool run pyright --verbose --project pyprojecttoml-with-config pyprojecttoml-with-config/file.py
    • Loads project pyproject.toml and therefore doesn't report unnecessary type ignore ✅
  • uv tool run pyright --verbose --project pyprojecttoml-without-config pyprojecttoml-without-config/file.py
    • Loads project pyproject.toml (warns that it has no "[tool.pyright]" section) and doesn't report unnecessary type ignore ❌

(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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions