Import: .py module wins over namespace-package dir (#10614)#10951
Open
tannewt wants to merge 1 commit intoadafruit:mainfrom
Open
Import: .py module wins over namespace-package dir (#10614)#10951tannewt wants to merge 1 commit intoadafruit:mainfrom
tannewt wants to merge 1 commit intoadafruit:mainfrom
Conversation
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>
dhalbert
requested changes
Apr 16, 2026
Collaborator
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When both
foo/(no init.py) andfoo.pyexisted on the filesystem,import foosilently imported the empty namespace package and skippedfoo.py. CPython picks the.pyin this case, and the docs define that precedence: regular package > module > namespace package.stat_module now probes for
__init__.py/.mpyinside 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_drivecan include files inside subdirectories.Fixes #10614.
The Claude LLM was used to generate the fix and the test.