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

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, 10 months ago
Right Patch Set: Created 3 years, 9 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 5136 matching lines...) Expand 10 before | Expand all | Expand 10 after
5147 } 5147 }
5148 if (skip_leading_underscores && 5148 if (skip_leading_underscores &&
5149 PyUnicode_Check(name) && 5149 PyUnicode_Check(name) &&
5150 PyUnicode_READY(name) != -1 && 5150 PyUnicode_READY(name) != -1 &&
5151 PyUnicode_READ_CHAR(name, 0) == '_') 5151 PyUnicode_READ_CHAR(name, 0) == '_')
5152 { 5152 {
5153 Py_DECREF(name); 5153 Py_DECREF(name);
5154 continue; 5154 continue;
5155 } 5155 }
5156 value = PyObject_GetAttr(v, name); 5156 value = PyObject_GetAttr(v, name);
5157 if (value == NULL) 5157 if (value == NULL && PyErr_ExceptionMatches(PyExc_AttributeError))
5158 { 5158 {
5159 if (!PyErr_ExceptionMatches(PyExc_AttributeError) || 5159 /* Issue #23477: if a circular import happens within a wildcard
5160 !PyUnicode_Check(name)) { 5160 import, some partially loaded modules may not have been saved
5161 err = -1; 5161 to the package's __dict__ yet, so we'll try getting them from
5162 } 5162 sys.modules before giving up.
5163 else { 5163 */
5164 /* Issue #23477: If a circular import happens within a wildcard 5164 PyErr_Clear();
5165 import, some partially loaded modules may not have been saved 5165 pkgname = _PyObject_GetAttrId(v, &PyId___name__);
5166 to the package's __dict__ yet, so try getting them from 5166 if (pkgname != NULL && PyUnicode_Check(pkgname))
5167 sys.modules before giving up. */ 5167 {
5168 PyErr_Clear(); 5168 fullmodname = PyUnicode_FromFormat("%U.%U", pkgname, name);
5169 pkgname = _PyObject_GetAttrId(v, &PyId___name__); 5169 if (fullmodname != NULL)
5170 if (pkgname != NULL && PyUnicode_Check(pkgname)) { 5170 {
5171 fullmodname = PyUnicode_FromFormat("%U.%U", pkgname, name); 5171 value = PyDict_GetItem(PyImport_GetModuleDict(),
5172 if (fullmodname == NULL) { 5172 fullmodname);
5173 err = -1; 5173 Py_XINCREF(value);
5174 } 5174 Py_DECREF(fullmodname);
5175 else {
5176 value = PyDict_GetItem(PyImport_GetModuleDict(),
5177 fullmodname);
5178 if (value == NULL) {
5179 PyErr_Format(PyExc_ImportError,
5180 "cannot import name %R",
5181 fullmodname);
5182 err = -1;
5183 }
5184 else {
5185 Py_INCREF(value);
5186 }
5187 Py_DECREF(fullmodname);
5188 }
5189 Py_DECREF(pkgname);
5190 } 5175 }
5191 } 5176 Py_DECREF(pkgname);
5177 }
5178 }
5179 if (value == NULL) {
5180 PyErr_Format(PyExc_ImportError, "cannot import name %R", name);
5181 err = -1;
5192 } 5182 }
5193 else if (PyDict_CheckExact(locals)) 5183 else if (PyDict_CheckExact(locals))
5194 err = PyDict_SetItem(locals, name, value); 5184 err = PyDict_SetItem(locals, name, value);
5195 else 5185 else
5196 err = PyObject_SetItem(locals, name, value); 5186 err = PyObject_SetItem(locals, name, value);
5197 Py_DECREF(name); 5187 Py_DECREF(name);
5198 Py_XDECREF(value); 5188 Py_XDECREF(value);
5199 if (err != 0) 5189 if (err != 0)
5200 break; 5190 break;
5201 } 5191 }
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
5326 Py_DECREF(l); 5316 Py_DECREF(l);
5327 return NULL; 5317 return NULL;
5328 } 5318 }
5329 PyList_SetItem(l, i, x); 5319 PyList_SetItem(l, i, x);
5330 } 5320 }
5331 return l; 5321 return l;
5332 #endif 5322 #endif
5333 } 5323 }
5334 5324
5335 #endif 5325 #endif
LEFTRIGHT

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