Message388901
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? |
|
Date |
User |
Action |
Args |
2021-03-17 00:26:14 | kaorihinata | set | recipients:
+ kaorihinata, brett.cannon, eric.smith |
2021-03-17 00:26:13 | kaorihinata | set | messageid: <1615940773.95.0.0552359944569.issue43477@roundup.psfhosted.org> |
2021-03-17 00:26:13 | kaorihinata | link | issue43477 messages |
2021-03-17 00:26:12 | kaorihinata | create | |
|