import os
from test import support
+from test.support.script_helper import assert_python_ok
try:
import _testcapi
"""LazyImportType should not be directly constructible."""
self.assertRaises(TypeError, types.LazyImportType, {}, "module")
+ @support.requires_subprocess()
+ def test_lazy_import_type_attributes_accessible(self):
+ """Check that static PyLazyImport_Type is initialized at startup."""
+ code = textwrap.dedent("""
+ lazy import json
+ print(globals()["json"].resolve)
+ """)
+ proc = assert_python_ok("-c", code)
+ self.assertIn(b"<built-in method resolve of lazy_import object at", proc.out)
+
class SyntaxRestrictionTests(unittest.TestCase):
"""Tests for syntax restrictions on lazy imports."""
#include "pycore_instruction_sequence.h" // _PyInstructionSequence_Type
#include "pycore_interpframe.h" // _PyFrame_Stackbase()
#include "pycore_interpolation.h" // _PyInterpolation_Type
+#include "pycore_lazyimportobject.h" // PyLazyImport_Type
#include "pycore_list.h" // _PyList_DebugMallocStats()
#include "pycore_long.h" // _PyLong_GetZero()
#include "pycore_memoryobject.h" // _PyManagedBuffer_Type
&PyGen_Type,
&PyGetSetDescr_Type,
&PyInstanceMethod_Type,
+ &PyLazyImport_Type,
&PyListIter_Type,
&PyListRevIter_Type,
&PyList_Type,