[Python-Dev] Re: Importing a submodule doesn't always set an attribute on its parent

2022-04-11 Thread dfremont--- via Python-Dev
Brett Cannon wrote: > So we don't want to strengthen the definition at > all; best we are comfortable with is put up a warning that you don't want > to do stuff with sys.modules unless you know what you're doing. OK, thanks for the clarification. Having read through the source of importlib one

[Python-Dev] Re: Importing a submodule doesn't always set an attribute on its parent

2022-04-11 Thread Brett Cannon
On Sat, Apr 9, 2022 at 1:53 PM dfremont--- via Python-Dev < python-dev@python.org> wrote: > Thanks, Brett. I understand why the behavior happens, I just don't > understand the decision to implement imports this way. Since there's no > warning in the documentation that removing items from

[Python-Dev] Re: Importing a submodule doesn't always set an attribute on its parent

2022-04-11 Thread Nick Coghlan
On Sun, 10 Apr 2022, 8:44 am Eric V. Smith, wrote: > On 4/9/2022 4:28 PM, Terry Reedy wrote: > > On 4/9/2022 5:09 AM, Arfrever Frehtes Taifersar Arahesis wrote: > >> > >> Not only deletion, but also random assignments: > > > > Ok. Change "Manual deletion of entries from sys.modules" to "Direct

[Python-Dev] Re: Importing a submodule doesn't always set an attribute on its parent

2022-04-09 Thread Eric V. Smith
On 4/9/2022 4:28 PM, Terry Reedy wrote: On 4/9/2022 5:09 AM, Arfrever Frehtes Taifersar Arahesis wrote: Not only deletion, but also random assignments: Ok.  Change "Manual deletion of entries from sys.modules" to "Direct manipulation of sys.modules" I'm not sure it's worth the hassle to

[Python-Dev] Re: Importing a submodule doesn't always set an attribute on its parent

2022-04-09 Thread dfremont--- via Python-Dev
Thanks, Brett. I understand why the behavior happens, I just don't understand the decision to implement imports this way. Since there's no warning in the documentation that removing items from sys.modules can break the fact that "import X.Y" defines "X.Y" (note that the "behind the curtain"

[Python-Dev] Re: Importing a submodule doesn't always set an attribute on its parent

2022-04-09 Thread Terry Reedy
On 4/9/2022 5:09 AM, Arfrever Frehtes Taifersar Arahesis wrote: 2022-04-09 04:24 UTC, Terry Reedy は書いた: Perhaps something intentionally vague like "Manual deletion of entries from sys.modules may invalidate statements above, even after re-imports." or "Manual deletion of entries from

[Python-Dev] Re: Importing a submodule doesn't always set an attribute on its parent

2022-04-09 Thread Christopher Barker
> Not only deletion, but also random assignments: > > >>> import sys > >>> import collections.abc > >>> sys.modules['collections'] = 1 > >>> import collections.abc > >>> collections.abc > Traceback (most recent call last): > File "", line 1, in > AttributeError: 'int' object has no attribute

[Python-Dev] Re: Importing a submodule doesn't always set an attribute on its parent

2022-04-09 Thread Arfrever Frehtes Taifersar Arahesis
2022-04-09 04:24 UTC, Terry Reedy は書いた: > Perhaps something intentionally vague like > > "Manual deletion of entries from sys.modules may invalidate statements > above, even after re-imports." > > or > > "Manual deletion of entries from sys.modules may result in surprising > behavior, even after

[Python-Dev] Re: Importing a submodule doesn't always set an attribute on its parent

2022-04-08 Thread Terry Reedy
On 4/8/2022 7:56 PM, Brett Cannon wrote: On Fri, Apr 8, 2022 at 4:38 PM dfremont--- via Python-Dev mailto:python-dev@python.org>> wrote: If you import A.B, then remove A from sys.modules and import A.B again, the newly-loaded version of A will not contain an attribute referring

[Python-Dev] Re: Importing a submodule doesn't always set an attribute on its parent

2022-04-08 Thread Brett Cannon
On Fri, Apr 8, 2022 at 4:38 PM dfremont--- via Python-Dev < python-dev@python.org> wrote: > Hello, > > I came across what seems like either a bug in the import system or a gap > in its documentation, so I'd like to run it by folks here to see if I > should submit a bug report. If there's