https://github.com/python/cpython/commit/c843cb758e56c2b759860504849250ee152b89dd commit: c843cb758e56c2b759860504849250ee152b89dd branch: main author: YiYi <[email protected]> committer: brettcannon <[email protected]> date: 2026-07-08T17:28:30Z summary:
gh-61310: Document package precedence over same-named modules (#153211) Co-authored-by: TheD0ubleC <[email protected]> Co-authored-by: Stan Ulbrych <[email protected]> files: M Doc/reference/import.rst diff --git a/Doc/reference/import.rst b/Doc/reference/import.rst index 4c8811560de2e3f..2ff88cb6b1fed54 100644 --- a/Doc/reference/import.rst +++ b/Doc/reference/import.rst @@ -665,6 +665,15 @@ shared libraries (e.g. ``.so`` files). When supported by the :mod:`zipimport` module in the standard library, the default path entry finders also handle loading all of these file types (other than shared libraries) from zipfiles. +Within a single :term:`path entry`, the default path entry finders check for a +:term:`regular package` first, then for extension modules, then for source +files, and finally for bytecode files. For example, if the same directory +contains both ``spam/__init__.py`` and ``spam.py``, ``import spam`` will +import the package from ``spam/__init__.py``. A directory without an +``__init__.py`` file is treated as a :term:`namespace package` portion only if +no matching module is found. Note that this does not override the order of the +:term:`import path`. + Path entries need not be limited to file system locations. They can refer to URLs, database queries, or any other location that can be specified as a string. _______________________________________________ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3//lists/python-checkins.python.org Member address: [email protected]
