Core and Builtins
-----------------
- or builtins for importing submodules or "from import". Fixed handling an
- error of non-string package name.
+ - Issue #27419: Standard __import__() no longer look up "__import__" in globals
++ or builtins for importing submodules or "from import". Fixed a crash if
++ raise a warning about unabling to resolve package from __spec__ or
++ __package__.
+
- Issue #27083: Respect the PYTHONCASEOK environment variable under Windows.
- Issue #27514: Make having too many statically nested blocks a SyntaxError
PyErr_SetString(PyExc_TypeError, "package must be a string");
goto error;
}
+ else if (spec != NULL && spec != Py_None) {
+ int equal;
+ PyObject *parent = PyObject_GetAttrString(spec, "parent");
+ if (parent == NULL) {
+ goto error;
+ }
+
+ equal = PyObject_RichCompareBool(package, parent, Py_EQ);
+ Py_DECREF(parent);
+ if (equal < 0) {
+ goto error;
+ }
+ else if (equal == 0) {
+ if (PyErr_WarnEx(PyExc_ImportWarning,
+ "__package__ != __spec__.parent", 1) < 0) {
+ goto error;
+ }
+ }
+ }
+ }
+ else if (spec != NULL && spec != Py_None) {
+ package = PyObject_GetAttrString(spec, "parent");
+ if (package == NULL) {
+ goto error;
+ }
+ else if (!PyUnicode_Check(package)) {
+ PyErr_SetString(PyExc_TypeError,
+ "__spec__.parent must be a string");
+ goto error;
+ }
}
else {
++ package = NULL;
+ if (PyErr_WarnEx(PyExc_ImportWarning,
+ "can't resolve package from __spec__ or __package__, "
+ "falling back on __name__ and __path__", 1) < 0) {
+ goto error;
+ }
+
package = _PyDict_GetItemId(globals, &PyId___name__);
if (package == NULL) {
PyErr_SetString(PyExc_KeyError, "'__name__' not in globals");