Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(80881)

Delta Between Two Patch Sets: Python/ceval.c

Issue 23447: Import fails when doing a circular import involving an `import *`
Left Patch Set: Created 3 years, 7 months ago
Right Patch Set: Created 3 years, 6 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Lib/test/test_import/__init__.py ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 1
2 /* Execute compiled code */ 2 /* Execute compiled code */
3 3
4 /* XXX TO DO: 4 /* XXX TO DO:
5 XXX speed up searching for keywords by using a dictionary 5 XXX speed up searching for keywords by using a dictionary
6 XXX document it! 6 XXX document it!
7 */ 7 */
8 8
9 /* enable more aggressive intra-module optimizations, where available */ 9 /* enable more aggressive intra-module optimizations, where available */
10 #define PY_LOCAL_AGGRESSIVE 10 #define PY_LOCAL_AGGRESSIVE
(...skipping 5145 matching lines...) Expand 10 before | Expand all | Expand 10 after
5156 value = PyObject_GetAttr(v, name); 5156 value = PyObject_GetAttr(v, name);
5157 if (value == NULL && PyErr_ExceptionMatches(PyExc_AttributeError)) 5157 if (value == NULL && PyErr_ExceptionMatches(PyExc_AttributeError))
5158 { 5158 {
5159 /* Issue #23477: if a circular import happens within a wildcard 5159 /* Issue #23477: if a circular import happens within a wildcard
5160 import, some partially loaded modules may not have been saved 5160 import, some partially loaded modules may not have been saved
5161 to the package's __dict__ yet, so we'll try getting them from 5161 to the package's __dict__ yet, so we'll try getting them from
5162 sys.modules before giving up. 5162 sys.modules before giving up.
5163 */ 5163 */
5164 PyErr_Clear(); 5164 PyErr_Clear();
5165 pkgname = _PyObject_GetAttrId(v, &PyId___name__); 5165 pkgname = _PyObject_GetAttrId(v, &PyId___name__);
5166 if (pkgname != NULL) 5166 if (pkgname != NULL && PyUnicode_Check(pkgname))
5167 { 5167 {
5168 fullmodname = PyUnicode_FromFormat("%U.%U", pkgname, name); 5168 fullmodname = PyUnicode_FromFormat("%U.%U", pkgname, name);
5169 if (fullmodname != NULL) 5169 if (fullmodname != NULL)
5170 { 5170 {
5171 value = PyDict_GetItem(PyImport_GetModuleDict(), 5171 value = PyDict_GetItem(PyImport_GetModuleDict(),
5172 fullmodname); 5172 fullmodname);
5173 if (value == NULL) 5173 Py_XINCREF(value);
5174 PyErr_Format(PyExc_ImportError,
5175 "cannot import name %R",
5176 name);
5177 else
5178 Py_INCREF(value);
5179 Py_DECREF(fullmodname); 5174 Py_DECREF(fullmodname);
5180 } 5175 }
5181 Py_DECREF(pkgname); 5176 Py_DECREF(pkgname);
5182 } 5177 }
5183 } 5178 }
5184 if (value == NULL) 5179 if (value == NULL) {
5180 PyErr_Format(PyExc_ImportError, "cannot import name %R", name);
5185 err = -1; 5181 err = -1;
5182 }
5186 else if (PyDict_CheckExact(locals)) 5183 else if (PyDict_CheckExact(locals))
5187 err = PyDict_SetItem(locals, name, value); 5184 err = PyDict_SetItem(locals, name, value);
5188 else 5185 else
5189 err = PyObject_SetItem(locals, name, value); 5186 err = PyObject_SetItem(locals, name, value);
5190 Py_DECREF(name); 5187 Py_DECREF(name);
5191 Py_XDECREF(value); 5188 Py_XDECREF(value);
5192 if (err != 0) 5189 if (err != 0)
5193 break; 5190 break;
5194 } 5191 }
5195 Py_DECREF(all); 5192 Py_DECREF(all);
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
5319 Py_DECREF(l); 5316 Py_DECREF(l);
5320 return NULL; 5317 return NULL;
5321 } 5318 }
5322 PyList_SetItem(l, i, x); 5319 PyList_SetItem(l, i, x);
5323 } 5320 }
5324 return l; 5321 return l;
5325 #endif 5322 #endif
5326 } 5323 }
5327 5324
5328 #endif 5325 #endif
LEFTRIGHT

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+