URL: http://github.com/python/cpython/pull/148111.patch
""", + } + + result = self._assert_subprocess_ok( + """ + import pkg.runner + print("OK") + """, + files, + ) + self.assertIn("OK", result.stdout) + class AdditionalSyntaxRestrictionTests(unittest.TestCase): """Additional syntax restriction tests per PEP 810.""" diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-04-04-22-20-00.gh-issue-148110.cL5x2Q.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-04-04-22-20-00.gh-issue-148110.cL5x2Q.rst new file mode 100644 index 00000000000000..dc7df0e4a299c9 --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2026-04-04-22-20-00.gh-issue-148110.cL5x2Q.rst @@ -0,0 +1,2 @@ +Fix :func:`sys.set_lazy_imports_filter` so relative lazy imports pass the +resolved imported module name to the filter callback. Patch by Pablo Galindo. diff --git a/Python/clinic/sysmodule.c.h b/Python/clinic/sysmodule.c.h index f8ae7f18acc809..dd603ae6668a3a 100644 --- a/Python/clinic/sysmodule.c.h +++ b/Python/clinic/sysmodule.c.h @@ -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."); diff --git a/Python/import.c b/Python/import.c index e298fbee536c1b..7aa96196ec1e10 100644 --- a/Python/import.c +++ b/Python/import.c @@ -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); diff --git a/Python/sysmodule.c b/Python/sysmodule.c index ce9c03bda7bd57..6298b080a0269f 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -2796,7 +2796,7 @@ 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]*/ From 6ec1b79cd3093a095d06dadfeea6c5083b2bbfc1 Mon Sep 17 00:00:00 2001 From: Pablo Galindo SalgadoNote: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: