mirror of
https://github.com/python/cpython.git
synced 2026-04-13 15:20:52 +00:00
gh-144851: Fix __lazy_import__ crash with user-defined filters (#144852)
This commit is contained in:
parent
3b276f3f59
commit
8bcb3eaa67
2 changed files with 9 additions and 0 deletions
|
|
@ -391,6 +391,11 @@ def test_dunder_lazy_import(self):
|
|||
import test.test_lazy_import.data.dunder_lazy_import
|
||||
self.assertNotIn("test.test_lazy_import.data.basic2", sys.modules)
|
||||
|
||||
def test_dunder_lazy_import_with_custom_filter(self):
|
||||
sys.set_lazy_imports_filter(lambda importer, imported, fromlist: False)
|
||||
import test.test_lazy_import.data.dunder_lazy_import
|
||||
self.assertIn("test.test_lazy_import.data.basic2", sys.modules)
|
||||
|
||||
def test_dunder_lazy_import_used(self):
|
||||
"""Using __lazy_import__ result should trigger module load."""
|
||||
import test.test_lazy_import.data.dunder_lazy_import_used
|
||||
|
|
|
|||
|
|
@ -4512,6 +4512,10 @@ _PyImport_LazyImportModuleLevelObject(PyThreadState *tstate,
|
|||
assert(!PyErr_Occurred());
|
||||
modname = Py_NewRef(Py_None);
|
||||
}
|
||||
if (fromlist == NULL) {
|
||||
assert(!PyErr_Occurred());
|
||||
fromlist = Py_NewRef(Py_None);
|
||||
}
|
||||
PyObject *args[] = {modname, name, fromlist};
|
||||
PyObject *res = PyObject_Vectorcall(filter, args, 3, NULL);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue