gh-148672: Document namespace subpackages inside regular packages#150056
Open
Taeknology wants to merge 1 commit into
Open
gh-148672: Document namespace subpackages inside regular packages#150056Taeknology wants to merge 1 commit into
Taeknology wants to merge 1 commit into
Conversation
The import system already creates implicit namespace packages for any subdirectory of a regular package that lacks an ``__init__.py`` file, per :pep:`420`. Document this behaviour in Doc/reference/import.rst so readers do not have to infer it from the PEP and from importlib internals.
Documentation build overview
|
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.
This documents the long-standing behaviour where a subdirectory of a
regular package that does not contain an
__init__.pyfile is importedas a namespace subpackage of that regular package, per
PEP 420.
The reference docs (
Doc/reference/import.rst) currently describe"Regular packages" and "Namespace packages" as two disjoint categories,
and do not mention that a namespace package can also be nested inside a
regular package. The behaviour is intentional (PEP 420 Specification;
implemented in
Lib/importlib/_bootstrap_external.pyFileFinder.find_spec), but is undocumented.This PR adds:
section pointing to the namespace package definition.
that namespace packages may also be nested inside a regular package.
Verified locally (Python 3.12.11)
I reproduced the documented behaviour against a CPython interpreter to
make sure the new wording matches what the import system actually does:
The interpreter's own
reprlabelsmyreg.empty_subandmyreg.empty_sub.deeperas(namespace), confirming this is theintended behaviour and not a bug, which is what the new paragraphs
document.
No code change. No
Misc/NEWS.dentry (docs-only).Fixes #148672