File tree Expand file tree Collapse file tree 2 files changed +13
-0
lines changed
Lib/test/test_lazy_import Expand file tree Collapse file tree 2 files changed +13
-0
lines changed Original file line number Diff line number Diff line change 1212import os
1313
1414from test import support
15+ from test .support .script_helper import assert_python_ok
1516
1617try :
1718 import _testcapi
@@ -219,6 +220,16 @@ def test_lazy_import_type_cant_construct(self):
219220 """LazyImportType should not be directly constructible."""
220221 self .assertRaises (TypeError , types .LazyImportType , {}, "module" )
221222
223+ @support .requires_subprocess ()
224+ def test_lazy_import_type_attributes_accessible (self ):
225+ """Check that static PyLazyImport_Type is initialized at startup."""
226+ code = textwrap .dedent ("""
227+ lazy import json
228+ print(globals()["json"].resolve)
229+ """ )
230+ proc = assert_python_ok ("-c" , code )
231+ self .assertIn (b"<built-in method resolve of lazy_import object at" , proc .out )
232+
222233
223234class SyntaxRestrictionTests (unittest .TestCase ):
224235 """Tests for syntax restrictions on lazy imports."""
Original file line number Diff line number Diff line change 1717#include "pycore_instruction_sequence.h" // _PyInstructionSequence_Type
1818#include "pycore_interpframe.h" // _PyFrame_Stackbase()
1919#include "pycore_interpolation.h" // _PyInterpolation_Type
20+ #include "pycore_lazyimportobject.h" // PyLazyImport_Type
2021#include "pycore_list.h" // _PyList_DebugMallocStats()
2122#include "pycore_long.h" // _PyLong_GetZero()
2223#include "pycore_memoryobject.h" // _PyManagedBuffer_Type
@@ -2540,6 +2541,7 @@ static PyTypeObject* static_types[] = {
25402541 & PyGen_Type ,
25412542 & PyGetSetDescr_Type ,
25422543 & PyInstanceMethod_Type ,
2544+ & PyLazyImport_Type ,
25432545 & PyListIter_Type ,
25442546 & PyListRevIter_Type ,
25452547 & PyList_Type ,
You can’t perform that action at this time.
0 commit comments