PEP 499: Resolve uses of the default role (#3397)

This commit is contained in:
Adam Turner 2023-09-01 20:27:29 +01:00 committed by GitHub
parent 27e9d90500
commit 47b79e09fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 14 deletions

View File

@ -182,29 +182,30 @@ 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.
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
* ``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__`
-------------------------------------
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.
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.
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
@ -219,7 +220,7 @@ module instance, not the running module instance.
However, the problem has been around as long as the ``-m`` command
line option and is encountered regularly, if infrequently, by others.
In addition to `issue 19702`_, the discrepancy around `__main__`
In addition to `issue 19702`_, the discrepancy around ``__main__``
is alluded to in :pep:`451` and a similar proposal (predating :pep:`451`)
is described in :pep:`395` under
:pep:`Fixing dual imports of the main module <395#fixing-dual-imports-of-the-main-module>`.