[issue43477] from x import * behavior inconsistent between module types.
Thomas J. Gallen
report at bugs.python.org
Tue Mar 16 20:26:13 EDT 2021
Thomas J. Gallen <kaori.hinata at gmail.com> added the comment:
Given the previous example, in test.py, replace:
```
print(test_module.test_submodule)
```
...with:
```
assert(not hasattr(test_module, "test_submodule"))
```
...because the issue is only the bottom half of `_find_and_load_unlocked`. Specifically, the chunk starting at line 1006:
```
if parent:
# Set the module as an attribute on its parent.
parent_module = sys.modules[parent]
child = name.rpartition('.')[2]
try:
setattr(parent_module, child, module)
except AttributeError:
msg = f"Cannot set an attribute on {parent!r} for child module {child!r}"
_warnings.warn(msg, ImportWarning)
```
The issue with these lines is that nothing here was requested by the user, and the actions you mentioned (preventing redundant/duplicate imports) is not handled by anything in, or relating to this code (at least, not that I've seen.) The module and all dependencies would still be loaded into `sys.modules` despite this code. If the module has already been loaded, then we'll never make it past `_find_and_load` to `_find_and_load_unlocked` anyway, as `_NEEDS_LOADING` will no longer match.
Does that make more sense?
----------
resolution: not a bug ->
status: closed -> open
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue43477>
_______________________________________
More information about the Python-bugs-list
mailing list