Eric Snow <ericsnowcurren...@gmail.com> added the comment:

Here is more detail on what happens when "from src import user_1, user_2, 
user_3" is executed in main.py:

1. the "src" module is imported
   a. not found in sys.modules
   b. file found on a sys.path entry (the directory main.py is in)
   c. the "src" module is created with __path__ set to the src directory
   d. the module is added to sys.modules
   e. src/__init__.py is executed
2. the "src.user_1" module is imported
   a. not found in sys.modules
   b. file found relative to src.__path__
   c. module created
   d. added to sys.modules
   e. executed
3. "from .common_object import OBJECT" is resolved to "from src.common_object 
import OBJECT"
4. "src.common_object" is imported (see 2)
5. src.common_object.OBJECT is created
6. "src.user_2" is imported (see 2)
7. "src.common_object" is already found in sys.modules and used
8. "src.user_3" is imported (see 2)
9. "common_object" is imported
   a. not found in sys.modules
   b. file found on a sys.path entry (the one you added in main.py)
   c. module created
   d. added to sys.modules
   e. executed
10. common_object.OBJECT is created

So the module created at (4) is different than the one at (9), even though they 
are imported from the same file.  Consequently, the OBJECT in each is likewise 
distinct.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue46806>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to