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 2008年06月27日 20:35 by schmir, last changed 2022年04月11日 14:56 by admin. This issue is now closed.
| Messages (7) | |||
|---|---|---|---|
| msg68850 - (view) | Author: Ralf Schmitt (schmir) | Date: 2008年06月27日 20:35 | |
The following short program work in python 2.5, but does die with a SystemError in python2.6: ~/ cat t.py #! /usr/bin/env python res = dict(__package__='foo') exec "from os import path" in res ~/ python2.5 t.py ~/ python2.6 t.py Traceback (most recent call last): File "t.py", line 4, in <module> exec "from os import path" in res File "<string>", line 1, in <module> SystemError: Parent module 'foo' not loaded I think this has been introduced with svn revision 42649 (http://hgpy.de/py/trunk/rev/54c72e1678d68ebbf274) Part of the diff reads: modules = PyImport_GetModuleDict(); parent = PyDict_GetItemString(modules, buf); if (parent == NULL) - parent = Py_None; + PyErr_Format(PyExc_SystemError, + "Parent module '%.200s' not loaded", buf); return parent; /* We expect, but can't guarantee, if parent != None, that: |
|||
| msg69270 - (view) | Author: Alyssa Coghlan (ncoghlan) * (Python committer) | Date: 2008年07月05日 00:40 | |
Hmm, setting an invalid value for __package__ will definitely break relative imports (see PEP 361), but it probably shouldn't be breaking absolute imports. |
|||
| msg69271 - (view) | Author: Alyssa Coghlan (ncoghlan) * (Python committer) | Date: 2008年07月05日 00:54 | |
One idea would be to change the import code to only produce a warning for a missing __package__ entry instead of a SystemError (reserving the SystemError for cases where the package name is derived from __name__ rather than being retrieved from the __package__ attribute). |
|||
| msg69383 - (view) | Author: Alyssa Coghlan (ncoghlan) * (Python committer) | Date: 2008年07月07日 12:49 | |
Bumped priority - an existing module shouldn't crash in 2.6 just because we started using __package__ as part of the import mechanism and that module happens to already set an attribute by that name. |
|||
| msg69385 - (view) | Author: Alyssa Coghlan (ncoghlan) * (Python committer) | Date: 2008年07月07日 12:54 | |
Adding to my personal to-do list for next beta. |
|||
| msg69610 - (view) | Author: Alyssa Coghlan (ncoghlan) * (Python committer) | Date: 2008年07月13日 15:07 | |
Fixed in r64915. The end result is that the import system now only emits a RuntimeWarning instead of raising SystemError if it can't find the parent module when attempting to perform an absolute import (regardless of whether the parent module name was derived from __package__ or from __name__). Explicit relative imports will still fail if __package__ is set incorrectly and setting __package__ to a non-string value will still result in a ValueError. |
|||
| msg69626 - (view) | Author: Ralf Schmitt (schmir) | Date: 2008年07月13日 21:07 | |
Thanks Nick for fixing this in a timely manner. BTW I've seen this when trying to run doctests with py.test. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:56:35 | admin | set | nosy:
+ barry github: 47471 |
| 2008年07月13日 21:07:57 | schmir | set | messages: + msg69626 |
| 2008年07月13日 15:07:35 | ncoghlan | set | status: open -> closed assignee: ncoghlan -> resolution: fixed messages: + msg69610 |
| 2008年07月07日 12:54:08 | ncoghlan | set | assignee: twouters -> ncoghlan messages: + msg69385 |
| 2008年07月07日 12:49:22 | ncoghlan | set | priority: release blocker messages: + msg69383 |
| 2008年07月05日 00:54:03 | ncoghlan | set | messages: + msg69271 |
| 2008年07月05日 00:40:35 | ncoghlan | set | nosy:
+ ncoghlan messages: + msg69270 |
| 2008年06月27日 21:02:50 | benjamin.peterson | set | assignee: twouters nosy: + twouters |
| 2008年06月27日 20:35:28 | schmir | create | |