Message241817
From Guido: It's definitely intentional, and it's fundamental to the package import design. We've had many implementations of package import (remember "ni.py"? last seen as "knee.py") and it was always there, because this is done as part of *submodule loading*. For better or for worse (and because I didn't know Java at the time :-) Python declares that if you write `import foo.bar` then later in your code you can use `foo.bar` to reference to the bar submodule of package foo. And the way this is done is to make each submodule an attribute of its parent package. This is done when the submodule is first loaded, and because of the strict separation between loading and importing, it is done no matter what form of import was used to load bar. I guess another thing to realize is that the globals of __init__.py are also the attribute namespace of the package. I'm not surprised it's in the reference manual -- that hasn't been updated thoroughly in ages, and I sometimes cry when I see it. :-) So please do clarify this for the benefit of future implementers. | |
| Date | User | Action | Args | | 2015-04-22 17:20:15 | barry | set | recipients: + barry, brett.cannon | | 2015-04-22 17:20:15 | barry | set | messageid: <1429723215.79.0.516170111156.issue24029@psf.upfronthosting.co.za> | | 2015-04-22 17:20:15 | barry | link | issue24029 messages | | 2015-04-22 17:20:15 | barry | create | | |