[issue43697] Importlib documentation does not cover how meta path finders should handle namespace packages

Brett Cannon report at bugs.python.org
Thu Apr 1 18:17:15 EDT 2021


Brett Cannon <brett at python.org> added the comment:

> What I've never really got clear in my mind is how dotted names get handled.

Essentially:

1. Check if parent is imported; if not then import (working your way all the way back to the top if necessary)
2. Ask the sys.meta_path finders if they can handle the module
3. Use the loader from the spec
4. Add the imported module as an attribute on the parent

If you start from https://github.com/python/cpython/blob/master/Lib/importlib/__init__.py#L108 you can see how it all works. The Python code is actually not that complicated, especially if you ignore all the old PEP 302 compatibility code 😉.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue43697>
_______________________________________


More information about the Python-bugs-list mailing list