Document the unexpected importing of sub-namespaces inside normal python packages/namespaces · Issue #148672 · python/cpython · GitHub
Skip to content

Document the unexpected importing of sub-namespaces inside normal python packages/namespaces #148672

Closed

Description

@pakal

Documentation

The documentation of python import system explains that "namespaces" are meant to scatter the submodules of a same root package among several places.
It doesn't mention any change to the subpackages of a python package, which SHOULD by default include a __init__.py to be importable.

However, the attached test shows that empty folders inside a normal package or namespaces are themselves importable, thus unexpectedly creating namespaces (without any possibility to scatter files in the filesystem, when the root package itself is a normal package).

If it's a normal behaviour of the importer, shouldn't it be documented ?
Or is it actually a bug, which surprisingly makes data folders (eg. assets/ subfolders of a package) importable ?
If so, is it too late to undo that, and enforce the invariant that - except root namespaces - only folders with a __init__.py in them can be importable subpackages ?

PythonNamespaceTests.zip

Linked PRs

Activity

  1. added
    docsDocumentation in the Doc dir
    on Apr 17, 2026
  2. brettcannon commented on May 8, 2026

    @brettcannon
    Member

    However, the attached test shows that empty folders inside a normal package or namespaces are themselves importable

    Yes, because those are also namespace packages. There no restriction that namespace packages can only be top-level (and I don't think they are documented as such).

    If it's a normal behaviour of the importer, shouldn't it be documented ?

    Sure, feel free to submit a PR if you're up for it! But I believe the docs simply don't exclude the possibility, so I think it's more of a "could" than "should".

    is it too late to undo that

    It's too late to change by about over decade (https://peps.python.org/pep-0420/). 😉

  3. changed the title [-]Document the unexpected importing of sub-namespaces inside normal python packages/namespaces (or treat it as bug)[/-] [+]Document the unexpected importing of sub-namespaces inside normal python packages/namespaces[/+] on May 8, 2026
  4. added a commit that references this issue on May 29, 2026
  5. added 4 commits that reference this issue on Jun 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions