Message317405
Yes, while weird, that's expected behaviour.
Rather than being due to absolute vs relative imports, the difference arises from the fact that in "import pkg.module", the request is explicitly for a submodule, so the submodule import always happens, whereas if you write "from func import attr", the child module import is only attempted if "func.attr" fails to resolve after "func" is imported.
$ echo "print(__name__)" > pkg/__init__.py
$ echo "print(__name__)" > pkg/submodule.py
$ python3 -c "import pkg; pkg.submodule = 1; import pkg.submodule; print(pkg.submodule)"
pkg
pkg.submodule
<module 'pkg.submodule' from '/home/ncoghlan/devel/misc/_play/pkg/submodule.py'>
$ python3 -c "import pkg; pkg.submodule = 1; from pkg import submodule; print(pkg.submodule)"
pkg
1 |
|
Date |
User |
Action |
Args |
2018-05-23 13:26:56 | ncoghlan | set | recipients:
+ ncoghlan, brett.cannon, r.david.murray, eric.snow, Rolf Campbell |
2018-05-23 13:26:56 | ncoghlan | set | messageid: <1527082016.51.0.682650639539.issue33547@psf.upfronthosting.co.za> |
2018-05-23 13:26:56 | ncoghlan | link | issue33547 messages |
2018-05-23 13:26:56 | ncoghlan | create | |
|