[issue19771] runpy should check ImportError.name before wrapping it

Martin Panter report at bugs.python.org
Sat Aug 8 03:43:57 CEST 2015


Martin Panter added the comment:

Patch v4 just uses an explicit encoding in the test suite rather than relying on the environment’s encoding.

Laura: I think my patch may already handle your case. Assuming this is one way to reproduce it:

$ mkdir test
$ : > test/__init__.py
$ python2 -c 'import test'
$ rm test/__init__.py
$ ./python -m test
/media/disk/home/proj/python/cpython/python: Error while finding spec for 'test.__main__' (<class 'ImportError'>: bad magic number in 'test': b'\x03\xf3\r\n'); 'test' is a package and cannot be directly executed
[Exit 1]
$ hg qpush --move issue_19771_runpy.patch.v4
applying issue_19771_runpy.patch.v4
now at: issue_19771_runpy.patch.v4
$ ./python -m test
/media/disk/home/proj/python/cpython/python: Error while finding spec for 'test.__main__' (ImportError: bad magic number in 'test': b'\x03\xf3\r\n')
[Exit 1]

Perhaps the error could be improved further, though. I guess the problem is there is a bad magic number in test/__init__.pyc. And I have no idea what the “finding spec” bit is about; it is meaningless noise to me.

----------
Added file: http://bugs.python.org/file40150/issue_19771_runpy.patch.v4

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue19771>
_______________________________________


More information about the Python-bugs-list mailing list