classification
Title: PEP 366 implementation
Type: enhancement Stage:
Components: Interpreter Core, Library (Lib) Versions: Python 3.0, Python 2.6
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: ncoghlan Nosy List: gvanrossum, ncoghlan
Priority: normal Keywords: patch

Created on 2007-11-22 14:22 by ncoghlan, last changed 2007-12-03 12:58 by ncoghlan. 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: Nick 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 <module>
   from . import test_support
ValueError: Attempted relative import in non-package
$

What's missing here?
msg58080 - (view) Author: Nick 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: Nick 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: Nick Coghlan (ncoghlan) * (Python committer) Date: 2007-12-03 12:58
Checked in as rev 59288.
History
Date User Action Args
2007-12-03 12:58:01ncoghlansetstatus: open -> closed
messages: + msg58120
2007-12-02 20:09:44gvanrossumsetmessages: + msg58098
2007-12-02 14:01:48ncoghlansetfiles: + pep_366_v2.diff
messages: + msg58087
2007-12-02 13:57:15ncoghlansetfiles: - pep_366_v1.diff
2007-12-02 07:49:12ncoghlansetmessages: + msg58080
2007-11-30 20:39:11gvanrossumsetassignee: gvanrossum -> ncoghlan
resolution: accepted
messages: + msg58003
2007-11-30 19:39:18gvanrossumsetassignee: gvanrossum
nosy: + gvanrossum
2007-11-22 14:22:16ncoghlancreate