classification
Title: Regression for executing packages
Type: behavior
Components: Interpreter Core Versions: Python 2.6
process
Status: closed Resolution: invalid
Dependencies: Superseder:
Assigned To: ncoghlan Nosy List: benjamin.peterson, ncoghlan
Priority: critical Keywords:

Created on 2008-05-04 00:36 by benjamin.peterson, last changed 2008-05-04 04:34 by ncoghlan.

Messages
msg66184 (view) Author: Benjamin Peterson (benjamin.peterson) Date: 2008-05-04 00:36
If I have a package like this:

pack/
    __init__.py

and __init__.py looks like this
if __name__ == "__main__":
    print "Spam"

python -m pack gives
one is a package and cannot be directly executed

This is regression from 2.5 where "Spam" would be printed.
msg66189 (view) Author: Nick Coghlan (ncoghlan) Date: 2008-05-04 04:34
The ability to execute packages was never intended, since doing so
breaks imports in a variety of subtle ways. It was actually a bug in 2.5
that it was permitted at all, so 2.6 not only disabled it again, but
also added a test to make sure it stays disabled (2.4 correctly rejected
it with an ImportError, just as 2.6 does).

Here's the relevant svn log entry:

r56509 | nick.coghlan | 2007-07-23 23:41:45 +1000 (Mon, 23 Jul 2007) | 5
lines

Correctly cleanup sys.modules after executing runpy relative import
tests
Restore Python 2.4 ImportError when attempting to execute a package
(as imports cannot be guaranteed to work properly if you try it)
History
Date User Action Args
2008-05-04 04:34:26ncoghlansetstatus: open -> closed
resolution: invalid
messages: + msg66189
2008-05-04 00:40:15benjamin.petersonsetassignee: ncoghlan
nosy: + ncoghlan
2008-05-04 00:36:17benjamin.petersoncreate