Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b3b65e6

Browse files
Issue #27419: Standard __import__() no longer look up "__import__" in globals
or builtins for importing submodules or "from import". Fixed handling an error of non-string package name.
1 parent dec25af commit b3b65e6

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ Release date: TBA
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #27419: Standard __import__() no longer look up "__import__" in globals
14+
or builtins for importing submodules or "from import". Fixed handling an
15+
error of non-string package name.
16+
1317
- Issue #27083: Respect the PYTHONCASEOK environment variable under Windows.
1418

1519
- Issue #27514: Make having too many statically nested blocks a SyntaxError

Python/import.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1438,6 +1438,7 @@ PyImport_ImportModuleLevelObject(PyObject *name, PyObject *given_globals,
14381438
}
14391439
else if (!PyUnicode_Check(package)) {
14401440
PyErr_SetString(PyExc_TypeError, "__name__ must be a string");
1441+
goto error;
14411442
}
14421443
Py_INCREF(package);
14431444

@@ -1525,15 +1526,10 @@ PyImport_ImportModuleLevelObject(PyObject *name, PyObject *given_globals,
15251526
_PyImport_AcquireLock();
15261527
#endif
15271528
/* From this point forward, goto error_with_unlock! */
1528-
if (PyDict_Check(globals)) {
1529-
builtins_import = _PyDict_GetItemId(globals, &PyId___import__);
1530-
}
1529+
builtins_import = _PyDict_GetItemId(interp->builtins_copy, &PyId___import__);
15311530
if (builtins_import == NULL) {
1532-
builtins_import = _PyDict_GetItemId(interp->builtins, &PyId___import__);
1533-
if (builtins_import == NULL) {
1534-
PyErr_SetString(PyExc_ImportError, "__import__ not found");
1535-
goto error_with_unlock;
1536-
}
1531+
PyErr_SetString(PyExc_ImportError, "__import__ not found");
1532+
goto error_with_unlock;
15371533
}
15381534
Py_INCREF(builtins_import);
15391535

0 commit comments

Comments
 (0)