Nick Coghlan <ncogh...@gmail.com> added the comment:

[Belatedly updating this issue with the current status as of March]

Cameron's implementation generally looks good, but there are couple of 
compatibility/migration questions that we need to consider, as spelled out in 
the PEP update that added me as BDFL-Delegate: 
https://github.com/python/peps/pull/946/files

* We need a generic porting guide entry to handle projects that turn out to 
have been relying on their name *not* being bound in sys.modules. For example, 
adding this preamble:

    if __name__ == "__main__":
        # To prevent inadvertent double imports, the -m
        # switch in Python 3.9+ defaults to aliasing __main__
        # under the executed module's import name. We actually
        # want the double import, so remove the alias if it exists
        import sys
        _main_module = sys.modules.get(__name__)
        _spec_module = sys.modules.get(__spec__.name)
        if _main_module is _spec_module:
            sys.modules.pop(__spec__.name)

We'd test the above snippet by adding it to the `pdb` module (and reverting the 
other compatibility changes to that module)

* We need to understand the implications for pickle compatibility, and provide 
a porting guide snippet, similar to the one above for explicitly requesting the 
double-import behaviour. For example:

    if __name__ == "__main__":
        # To prevent inadvertent double imports, the -m
        # switch in Python 3.9+ defaults to aliasing __main__
        # under the executed module's import name. We need
        # pickle to use the real module name for objects from
        # __main__ though, so we set the import name here
        _running_as_main = True
        __name__ = __spec__.name

----------

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

Reply via email to