Skip to content

Import: .py module wins over namespace-package dir (#10614)#10951

Open
tannewt wants to merge 1 commit intoadafruit:mainfrom
tannewt:fix-issue-10614
Open

Import: .py module wins over namespace-package dir (#10614)#10951
tannewt wants to merge 1 commit intoadafruit:mainfrom
tannewt:fix-issue-10614

Conversation

@tannewt
Copy link
Copy Markdown
Member

@tannewt tannewt commented Apr 16, 2026

When both foo/ (no init.py) and foo.py existed on the filesystem, import foo silently imported the empty namespace package and skipped foo.py. CPython picks the .py in this case, and the docs define that precedence: regular package > module > namespace package.

stat_module now probes for __init__.py/.mpy inside the directory first, then falls back to .py/.mpy, and only treats the bare directory as a namespace package when neither exists.

Adds a native_sim regression test and extends the test harness so circuitpy_drive can include files inside subdirectories.

Fixes #10614.

The Claude LLM was used to generate the fix and the test.

When both `foo/` (no __init__.py) and `foo.py` existed on the
filesystem, `import foo` silently imported the empty namespace package
and skipped `foo.py`. CPython picks the `.py` in this case, and the
docs define that precedence: regular package > module > namespace
package.

stat_module now probes for `__init__.py`/`.mpy` inside the directory
first, then falls back to `.py`/`.mpy`, and only treats the bare
directory as a namespace package when neither exists.

Adds a native_sim regression test and extends the test harness so
`circuitpy_drive` can include files inside subdirectories.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Collaborator

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this test should be in tests/. It is not port-specific, and does not need to be tested under zephyr.

@tannewt if you still have the Claude session available, it could be asked to move the test to tests/import. That directory has a number of example packages and files to import.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Directory without code takes import precedent over .py file

2 participants