-
-
Notifications
You must be signed in to change notification settings - Fork 30.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bpo-36375: PEP 499 implementation: "python -m foo" binds the main module as both __main__ and foo in sys.modules #12490
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just adding a blocking review to ensure the PR isn't merged until after the PEP has been reviewed.
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
@@ -1531,8 +1532,7 @@ def _runmodule(self, module_name): | |||
import runpy | |||
mod_name, mod_spec, code = runpy._get_module_details(module_name) | |||
self.mainpyfile = self.canonic(code.co_filename) | |||
import __main__ | |||
__main__.__dict__.clear() | |||
__main__ = types.ModuleType(module_name, 'New __main__ module for pdb.') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't interact correctly with the interpreter's -i
switch, as that always drops you into the original __main__
namespace, even if it's been rebound in sys.modules
by the application code.
@cameron-simpson This is looking pretty good, but there are still some backwards compatibility risks that we're going to have to investigate before the PEP can be approved. I'm officially the design & implementation reviewer for this PEP now, so I added the two key questions/concerns that I'm currently aware of to a new section: python/peps#946 |
974f062
to
88a5564
Compare
…nd sys.modules[foo]
…tinct new __main__ module With PEP499 __main__ is aliased as the canonical name of the -m module. When pdb is invoked via "python -m pdb" it can no longer rewrite the symbol table of the existing __main__ module because that is pdb itself. Instead we construct a new module and insert it as sys.modules['__main__'].
…03-20-00-38-35.bpo-36375.d178R0.rst
88a5564
to
a4b7de6
Compare
Closing this, as the linked issue has been closed. |
This contains documentation updates,
runpy.py
implementation, two unit tests and a fix forLib/pdb.py
to accomodate new aliasing of__main__
as the module's canonical name.A run of "make test" on my El Capitan Mac here now shows the following failures:
Of these:
test_c_locale_coercion appears to be due to differences between my OS release and presumably more modern Darwin releases: various "utf-8" vs "ascii" mismatches in the output.
text_xmlrpc seems to run forever, here
the other tests fail for network based reasons.
WRT to a run against the master branch, the failure set is the same.
I cannot reproduce the hashlib based failures seen by Travis on my earlier PR. It will be interesting to see what Travis says now.
https://bugs.python.org/issue36375