Issue 1487: PEP 366 implementation (original) (raw)

Created on 2007-11-22 14:22 by ncoghlan, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
pep_366_v2.diff ncoghlan,2007-12-02 14:01
Messages (6)
msg57761 - (view) Author: Alyssa Coghlan (ncoghlan) * (Python committer) Date: 2007-11-22 14:22
Patch to implement PEP 366. Note that it doesn't implement precisely the semantics described in the version of the PEP posted in July, as some of those ideas didn't prove feasible due to the fact that imp.new_module can't tell the difference between normal modules and packages. An updated version of the PEP will be posted shortly to correct those problems.
msg58003 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2007-11-30 20:39
I think the implementation is fine too (others will have to check it more carefully) but I noticed that the promised functionality of -m doesn't work yet: I created a file Lib/test/foo.py whose sole contents was "from . import test_support". Then I tried to import this using -m: $ ./python.exe -m test.foo Traceback (most recent call last): File "/Users/guido/p/Lib/runpy.py", line 104, in _run_module_as_main "__main__", fname, loader) File "/Users/guido/p/Lib/runpy.py", line 34, in _run_code exec code in run_globals File "/Users/guido/p/Lib/test/foo.py", line 1, in from . import test_support ValueError: Attempted relative import in non-package $ What's missing here?
msg58080 - (view) Author: Alyssa Coghlan (ncoghlan) * (Python committer) Date: 2007-12-02 07:49
I forgot to update the special _run_module_as_main variant when I modified run_module. I'll modify the patch to fix that and to test '-m' explicitly in test_cmd_line_script.
msg58087 - (view) Author: Alyssa Coghlan (ncoghlan) * (Python committer) Date: 2007-12-02 14:01
Posted v2 of the patch, which fixes the problem Guido noted, and improved the tests to make sure __package__ is being set correctly. There's also now an explicit test for using -m on a module inside a package (which proved harder to write than I expected - it isn't easy to fiddle with sys.path when the subprocess is running python with the -E flag!).
msg58098 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2007-12-02 20:09
Great, now check it in! On Dec 2, 2007 6:01 AM, Nick Coghlan <report@bugs.python.org> wrote: > > Nick Coghlan added the comment: > > Posted v2 of the patch, which fixes the problem Guido noted, and > improved the tests to make sure __package__ is being set correctly. > There's also now an explicit test for using -m on a module inside a > package (which proved harder to write than I expected - it isn't easy to > fiddle with sys.path when the subprocess is running python with the -E > flag!). > > Added file: http://bugs.python.org/file8852/pep_366_v2.diff > > > __________________________________ > Tracker <report@bugs.python.org> > <http://bugs.python.org/issue1487> > __________________________________
msg58120 - (view) Author: Alyssa Coghlan (ncoghlan) * (Python committer) Date: 2007-12-03 12:58
Checked in as rev 59288.
History
Date User Action Args
2022-04-11 14:56:28 admin set github: 45828
2007-12-03 12:58:01 ncoghlan set status: open -> closedmessages: +
2007-12-02 20:09:44 gvanrossum set messages: +
2007-12-02 14:01:48 ncoghlan set files: + pep_366_v2.diffmessages: +
2007-12-02 13:57:15 ncoghlan set files: - pep_366_v1.diff
2007-12-02 07:49:12 ncoghlan set messages: +
2007-11-30 20:39:11 gvanrossum set assignee: gvanrossum -> ncoghlanresolution: acceptedmessages: +
2007-11-30 19:39:18 gvanrossum set assignee: gvanrossumnosy: + gvanrossum
2007-11-22 14:22:16 ncoghlan create