gh-148110: Resolve lazy import filter names for relative imports (#148111)

This commit is contained in:
Pablo Galindo Salgado 2026-04-06 22:29:02 +01:00 committed by GitHub
parent a0c57a8d17
commit ca960b6f38
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 197 additions and 8 deletions

View file

@ -1830,7 +1830,7 @@ PyDoc_STRVAR(sys_set_lazy_imports_filter__doc__,
"would otherwise be enabled. Returns True if the import is still enabled\n"
"or False to disable it. The callable is called with:\n"
"\n"
"(importing_module_name, imported_module_name, [fromlist])\n"
"(importing_module_name, resolved_imported_module_name, [fromlist])\n"
"\n"
"Pass None to clear the filter.");
@ -2121,4 +2121,4 @@ exit:
#ifndef SYS_GETANDROIDAPILEVEL_METHODDEF
#define SYS_GETANDROIDAPILEVEL_METHODDEF
#endif /* !defined(SYS_GETANDROIDAPILEVEL_METHODDEF) */
/*[clinic end generated code: output=adbadb629b98eabf input=a9049054013a1b77]*/
/*[clinic end generated code: output=e8333fe10c01ae66 input=a9049054013a1b77]*/

View file

@ -4523,7 +4523,7 @@ _PyImport_LazyImportModuleLevelObject(PyThreadState *tstate,
assert(!PyErr_Occurred());
fromlist = Py_NewRef(Py_None);
}
PyObject *args[] = {modname, name, fromlist};
PyObject *args[] = {modname, abs_name, fromlist};
PyObject *res = PyObject_Vectorcall(filter, args, 3, NULL);
Py_DECREF(modname);

View file

@ -2796,14 +2796,14 @@ The filter is a callable which disables lazy imports when they
would otherwise be enabled. Returns True if the import is still enabled
or False to disable it. The callable is called with:
(importing_module_name, imported_module_name, [fromlist])
(importing_module_name, resolved_imported_module_name, [fromlist])
Pass None to clear the filter.
[clinic start generated code]*/
static PyObject *
sys_set_lazy_imports_filter_impl(PyObject *module, PyObject *filter)
/*[clinic end generated code: output=10251d49469c278c input=2eb48786bdd4ee42]*/
/*[clinic end generated code: output=10251d49469c278c input=fd51ed8df6ab54b7]*/
{
if (PyImport_SetLazyImportsFilter(filter) < 0) {
return NULL;