Thomas J. Gallen <kaori.hin...@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 <rep...@bugs.python.org>
<https://bugs.python.org/issue43477>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to