New submission from Martin Panter: The load_module() API adds an entry to sys.modules when loading a submodule, but does not add the submodule as an attribute in the parent package. I am no expert on PEP 302 or the import system, but this feels like a bug to me:
>>> import sys, pkgutil >>> loader = pkgutil.find_loader("xml.etree") >>> loader.load_module("xml.etree") <module 'xml.etree' from '/usr/lib/python3.4/xml/etree/__init__.py'> >>> sys.modules["xml.etree"] # Entry added, per documentation and PEP 302 <module 'xml.etree' from '/usr/lib/python3.4/xml/etree/__init__.py'> >>> hasattr(sys.modules["xml"], "etree") # But not linked to parent! False >>> import xml.etree >>> xml.etree # Broken :( Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'module' object has no attribute 'etree' ---------- messages: 252753 nosy: martin.panter priority: normal severity: normal status: open title: load_module() does not link submodule to parent package type: behavior versions: Python 2.7, Python 3.4, Python 3.5, Python 3.6 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue25372> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com