On 4/8/2022 7:56 PM, Brett Cannon wrote:

On Fri, Apr 8, 2022 at 4:38 PM dfremont--- via Python-Dev <[email protected] <mailto:[email protected]>> 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 to B.
...
    for example PLR 5.7 states that "'import XXX.YYY.ZZZ' should expose
    'XXX.YYY.ZZZ' as a usable expression".

And it did. But then you went behind the curtain and moved stuff around.

    Finally, it violates the "invariant" stated in PLR 5.4.2 that if 'A'
    and 'A.B' both appear in sys.modules, then A.B must be defined and
    refer to sys.modules['A.B'].

That isn't an invariant that holds when you delete things outside of the import system; that statement is what the import system /does/, not what the import system guarantees to always be true.
...
Feel free to propose some language to update the docs,

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 re-imports."

--
Terry Jan Reedy

_______________________________________________
Python-Dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/7CMQMWJJMM7RUDWUQXL3MW64KL4VW3P6/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to