PEP 499: Delegate to Nick Coghlan (#946)

Also updates the PEP with links to the reference implementation,
and adds an Open Questions section to highlight known areas of
compatibility risk.
This commit is contained in:
Nick Coghlan 2019-03-24 22:03:37 +10:00 committed by GitHub
parent 15f60095ab
commit e491484ce8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 46 additions and 0 deletions

View File

@ -3,6 +3,7 @@ Title: ``python -m foo`` should bind ``sys.modules['foo']`` in addition to ``sys
Version: $Revision$
Last-Modified: $Date$
Author: Cameron Simpson <cs@cskk.id.au>, Chris Angelico <rosuav@gmail.com>, Joseph Jevnik <joejev@gmail.com>
BDFL-Delegate: Nick Coghlan
Status: Draft
Type: Standards Track
Content-Type: text/x-rst
@ -152,6 +153,51 @@ where ``__name__`` is expected to be "__main__".
This PEP explicitly preserves that semantic.
Reference Implementation
========================
`BPO 36375 <https://bugs.python.org/issue36375>`_ is the issue tracker entry
for the PEP's reference implementation, with the current draft PR being
available `on GitHub <https://github.com/python/cpython/pull/12490>`_.
Open Questions
==============
This proposal does raise some backwards compatibility concerns, and these will
need to be well understood, and either a deprecation process designed, or clear
porting guidelines provided.
Pickle compatibility
--------------------
If no changes are made to the pickle module, then pickles that were previously
being written with the correct module name (due to a dual import) may start
being written with `__main__` as their module name instead, and hence fail to be
loaded correctly by other projects.
Scenarios to be checked:
* `python script.py` writing, `python -m script` reading
* `python -m script` writing, `python script.py` reading
* `python -m script` writing, `python some_other_app.py` reading
* `old_python -m script` writing, `new_python -m script` reading
* `new_python -m script` writing, `old_python -m script` reading
Projects that special-case `__main__`
-------------------------------------
In order to get the regression test suite to pass, the current reference
implementation had to patch `pdb` to avoid destroying its own global namespace.
This suggests there may be a broader compatibility issue where some scripts are
relying on direct execution and import giving different namespaces (just as
package execution keeps the two separate by executing the `__main__` submodule
in the `__main__` namespace, while the package name references the `__init__`
file as usual.
Background
==========