This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2012年11月20日 15:17 by barry, last changed 2022年04月11日 14:57 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| 16514.diff | barry, 2012年11月20日 16:13 | review | ||
| Messages (7) | |||
|---|---|---|---|
| msg175996 - (view) | Author: Barry A. Warsaw (barry) * (Python committer) | Date: 2012年11月20日 15:17 | |
When sys.path[0] is None, attempting to import a module produces a cryptic chained traceback. This is a regression from 3.2 where the import would succeed. The basic issue is that in 3.2's import.c, non-string/bytes items on sys.path are essentially ignored (see the loop in import.c:1708 find_module()) while they are not ignored in 3.3's importlib. This means that because zipimporter.zipimiporter is by default the first thing on sys.path_hooks, zipimporter.zipimporter(None) gets called. This raises a TypeError which starts the chained exception. Note that the fact that zipimporter.zipimporter(None) raises a TypeError is *not* a regression. The regression is that None makes its way to sys.path_hooks at all. I think this will be relatively easy to fix, if we agree that the current regressive behavior is a bug. |
|||
| msg176000 - (view) | Author: Barry A. Warsaw (barry) * (Python committer) | Date: 2012年11月20日 16:13 | |
Patch for 3.3, omitting the requisite importlib.h change. |
|||
| msg176001 - (view) | Author: Barry A. Warsaw (barry) * (Python committer) | Date: 2012年11月20日 16:14 | |
Oh, the patch includes the removal of some unused imports from test_path.py, thanks to pyflakes. |
|||
| msg176006 - (view) | Author: Eric V. Smith (eric.smith) * (Python committer) | Date: 2012年11月20日 16:51 | |
I agree it's a bug. And the fix looks good to me. Having said that: I haven't looked at the import.c version to verify what is happening. Does the test pass under 3.2? |
|||
| msg176007 - (view) | Author: Barry A. Warsaw (barry) * (Python committer) | Date: 2012年11月20日 16:57 | |
Oh, btw, I intend to add documentation that makes explicit: * sys.path entries must be strings or bytes, everything else is ignored * path importers should expect strings or bytes * the encoding of bytes is left to the individual path hooks to define, however it it can't decode the bytes it should ignore the path entry or raise an ImportError (effectively ignoring it anyway). |
|||
| msg176021 - (view) | Author: Barry A. Warsaw (barry) * (Python committer) | Date: 2012年11月20日 20:01 | |
On Nov 20, 2012, at 04:51 PM, Eric V. Smith wrote:
>I agree it's a bug. And the fix looks good to me.
Thanks.
>Having said that: I haven't looked at the import.c version to verify what is
>happening. Does the test pass under 3.2?
Yep. See below. When you take a look at the path_hooks iteration loop,
you'll see why.
-----snip snip-----
import sys
sys.path.insert(0, None)
sys.path_importer_cache.pop(None, None)
sys.modules.pop('email', None)
import email
print(email)
-----snip snip-----
% python3.2 /tmp/foo.py
<module 'email' from '/usr/lib/python3.2/email/__init__.py'>
% python3.3 /tmp/foo.py
Traceback (most recent call last):
File "<frozen importlib._bootstrap>", line 1271, in _path_importer_cache
KeyError: None
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/tmp/foo.py", line 7, in <module>
import email
File "<frozen importlib._bootstrap>", line 1561, in _find_and_load
File "<frozen importlib._bootstrap>", line 1519, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1473, in _find_module
File "<frozen importlib._bootstrap>", line 1308, in find_module
File "<frozen importlib._bootstrap>", line 1284, in _get_loader
File "<frozen importlib._bootstrap>", line 1273, in _path_importer_cache
File "<frozen importlib._bootstrap>", line 1254, in _path_hooks
TypeError: 'NoneType' object is not iterable
Error in sys.excepthook:
Traceback (most recent call last):
File "<frozen importlib._bootstrap>", line 1271, in _path_importer_cache
KeyError: None
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 58, in apport_excepthook
from cStringIO import StringIO
File "<frozen importlib._bootstrap>", line 1561, in _find_and_load
File "<frozen importlib._bootstrap>", line 1519, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1473, in _find_module
File "<frozen importlib._bootstrap>", line 1308, in find_module
File "<frozen importlib._bootstrap>", line 1284, in _get_loader
File "<frozen importlib._bootstrap>", line 1273, in _path_importer_cache
File "<frozen importlib._bootstrap>", line 1254, in _path_hooks
TypeError: 'NoneType' object is not iterable
Original exception was:
Traceback (most recent call last):
File "<frozen importlib._bootstrap>", line 1271, in _path_importer_cache
KeyError: None
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/tmp/foo.py", line 7, in <module>
import email
File "<frozen importlib._bootstrap>", line 1561, in _find_and_load
File "<frozen importlib._bootstrap>", line 1519, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1473, in _find_module
File "<frozen importlib._bootstrap>", line 1308, in find_module
File "<frozen importlib._bootstrap>", line 1284, in _get_loader
File "<frozen importlib._bootstrap>", line 1273, in _path_importer_cache
File "<frozen importlib._bootstrap>", line 1254, in _path_hooks
TypeError: 'NoneType' object is not iterable
|
|||
| msg176025 - (view) | Author: Roundup Robot (python-dev) (Python triager) | Date: 2012年11月20日 20:35 | |
New changeset 291406748217 by Barry Warsaw in branch '3.3': - Issue #16514: Fix regression causing a traceback when sys.path[0] is None http://hg.python.org/cpython/rev/291406748217 New changeset a82ee9a1457a by Barry Warsaw in branch 'default': - Issue #16514: Fix regression causing a traceback when sys.path[0] is None http://hg.python.org/cpython/rev/a82ee9a1457a |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:38 | admin | set | github: 60718 |
| 2012年11月22日 02:40:01 | jcea | set | nosy:
+ jcea |
| 2012年11月20日 20:55:30 | barry | set | status: open -> closed resolution: fixed |
| 2012年11月20日 20:35:37 | python-dev | set | nosy:
+ python-dev messages: + msg176025 |
| 2012年11月20日 20:14:40 | barry | set | title: Cryptic traceback when sys.path -> Cryptic traceback when sys.path[0] is None |
| 2012年11月20日 20:01:37 | barry | set | messages:
+ msg176021 title: Cryptic traceback when sys.path[0] is None -> Cryptic traceback when sys.path |
| 2012年11月20日 17:43:03 | chris.jerdonek | set | nosy:
+ chris.jerdonek |
| 2012年11月20日 16:57:35 | barry | set | messages: + msg176007 |
| 2012年11月20日 16:51:38 | eric.smith | set | messages: + msg176006 |
| 2012年11月20日 16:23:39 | barry | set | nosy:
+ brett.cannon, jaraco, eric.smith, eric.snow |
| 2012年11月20日 16:14:02 | barry | set | messages: + msg176001 |
| 2012年11月20日 16:13:09 | barry | set | files:
+ 16514.diff keywords: + patch messages: + msg176000 |
| 2012年11月20日 15:17:15 | barry | create | |