Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Lib/test/test_lazy_import/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import os

from test import support
from test.support.script_helper import assert_python_ok

try:
import _testcapi
Expand Down Expand Up @@ -219,6 +220,16 @@ def test_lazy_import_type_cant_construct(self):
"""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."""
Expand Down
2 changes: 2 additions & 0 deletions Objects/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#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
Expand Down Expand Up @@ -2540,6 +2541,7 @@ static PyTypeObject* static_types[] = {
&PyGen_Type,
&PyGetSetDescr_Type,
&PyInstanceMethod_Type,
&PyLazyImport_Type,
&PyListIter_Type,
&PyListRevIter_Type,
&PyList_Type,
Expand Down
Loading