◐ Shell
reader mode source ↗
Skip to content
Merged
Show file tree
Changes from all commits
File filter
Conversations
Jump to
Diff view
Apply and reload
Show whitespace
Diff view
Apply and reload
31 changes: 31 additions & 0 deletions Lib/test/test_lazy_import/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,26 @@ def test_basic_used(self):
import test.test_lazy_import.data.basic_used
self.assertIn("test.test_lazy_import.data.basic2", sys.modules)


class GlobalLazyImportModeTests(unittest.TestCase):
"""Tests for sys.set_lazy_imports() global mode control."""
Expand Down Expand Up @@ -385,6 +405,17 @@ def test_lazy_import_pkg_cross_import(self):
self.assertEqual(type(g["x"]), int)
self.assertEqual(type(g["b"]), types.LazyImportType)


class DunderLazyImportTests(unittest.TestCase):
"""Tests for __lazy_import__ builtin function."""
Expand Down
4 changes: 4 additions & 0 deletions Lib/test/test_lazy_import/data/module_with_getattr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
5 changes: 5 additions & 0 deletions Lib/test/test_lazy_import/data/pkg/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
x = 42
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
19 changes: 19 additions & 0 deletions Objects/moduleobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1307,6 +1307,25 @@ _Py_module_getattro_impl(PyModuleObject *m, PyObject *name, int suppress)
attr = _PyObject_GenericGetAttrWithDict((PyObject *)m, name, NULL, suppress);
if (attr) {
if (PyLazyImport_CheckExact(attr)) {
PyObject *new_value = _PyImport_LoadLazyImportTstate(
PyThreadState_GET(), attr);
if (new_value == NULL) {
Expand Down
Loading
Toggle all file notes Toggle all file annotations