[New-bugs-announce] [issue25372] load_module() does not link submodule to parent package
Martin Panter
report at bugs.python.org
Sun Oct 11 04:47:12 CEST 2015
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 <report at bugs.python.org>
<http://bugs.python.org/issue25372>
_______________________________________
More information about the New-bugs-announce
mailing list