[Python] pyright can't resolve imports in modules with their own pyproject.toml

Discussão em 'Python' iniciado por Stack, Abril 10, 2025.

  1. Stack

    Stack Membro Participativo

    Working with a mono-repository structured as so:

    - pyproject.toml (root workspace, references other members)
    src
    ├── application
    │ └── service.py
    ├── domain
    │ ├── headroom
    │ │ └── service.py
    │ ├── hosting_capacity
    │ │ └── service.py
    │ ├── model_free_engine
    │ │ └── service.py
    │ └── shared
    ├── entrypoint
    │ ├── api
    │ │ ├── main.py
    │ │ └── pyproject.toml
    │ └── worker
    │ ├── main.py
    │ └── pyproject.toml
    ├── infrastructure
    └── libs
    └── schemas
    └── pyproject.toml


    Any code within any sub folder with its own pyproject.toml cannot resolve imports. Imports a absolute like so:

    # entrypoint/api/main.py

    from application.service import Service

    • entrypoint/worker
    • entrypoint/api
    • libs/schemas

    However folders that do not have a pyproject.toml are fine:

    • application
    • domain
    • infrastructure

    I have tried various pyrightconfig.json settings both at the root and in the modules and nothing seems to help pyright other than if I DELETE the pyproject.toml from each.

    Example config in root.

    {
    "typeCheckingMode": "strict",
    "reportMissingImports": true,
    "reportMissingTypeStubs": false,
    "include": [
    "src"
    ],
    "extraPaths": [
    "src",
    "src/entrypoint/api",
    "src/entrypoint/worker",
    "src/libs/schemas"
    ]
    }

    Continue reading...

Compartilhe esta Página