Skip to content

"__path__" is not a known attribute of a module without __init__.py #10692

@rijenkii

Description

@rijenkii

Describe the bug
I am trying to import a module without __init__.py and read its __path__. Accessing it works at runtime, but pyright reports that there is no such attribute.

Code or Screenshots
Directory tree:

drwx------@  - rijenkii 10 Jul 11:28 .
drwxr-xr-x@  - rijenkii 10 Jul 11:28 └── src
drwxr-xr-x@  - rijenkii 10 Jul 11:32     └── app
.rw-r--r--@ 52 rijenkii 10 Jul 11:29         ├── main.py
drwxr-xr-x@  - rijenkii 10 Jul 11:28         └── namespace

main.py:

import app.namespace

print(app.namespace.__path__)

main.py output:

$ PYTHONPATH=src uv run python -m app.main
_NamespacePath(['/tmp/tmp.oDLOLEveoQ/src/app/namespace'])

pyright output:

$ uv run --with pyright==1.1.403 pyright .
/tmp/tmp.oDLOLEveoQ/src/app/main.py
  /tmp/tmp.oDLOLEveoQ/src/app/main.py:3:21 - error: "__path__" is not a known attribute of module "app.namespace" (reportAttributeAccessIssue)
1 error, 0 warnings, 0 informations 

Repro setup commands

cd $(mktemp -d)
mkdir -p src/app/namespace
echo -e 'import app.namespace\n\nprint(app.namespace.__path__)' >src/app/main.py

VS Code extension or command-line
CLI, version 1.1.403.

Metadata

Metadata

Assignees

No one assigned

    Labels

    addressed in next versionIssue is fixed and will appear in next published versionbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions