This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author martin.panter
Recipients martin.panter
Date 2015-10-11.02:47:10
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1444531632.83.0.513711320874.issue25372@psf.upfronthosting.co.za>
In-reply-to
Content
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'
History
Date User Action Args
2015-10-11 02:47:12martin.pantersetrecipients: + martin.panter
2015-10-11 02:47:12martin.pantersetmessageid: <1444531632.83.0.513711320874.issue25372@psf.upfronthosting.co.za>
2015-10-11 02:47:12martin.panterlinkissue25372 messages
2015-10-11 02:47:10martin.pantercreate