Skip to content

Commit c5efb20

Browse files
committed
Expose LazyImportType in types module
1 parent 46b3b75 commit c5efb20

File tree

5 files changed

+6
-9
lines changed

5 files changed

+6
-9
lines changed

Lib/importlib/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959

6060
from ._bootstrap import __import__
6161

62-
from _imp import lazy_import, set_lazy_imports
62+
from _imp import set_lazy_imports
6363

6464

6565
def invalidate_caches():

Lib/test/test_import/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2790,7 +2790,7 @@ def test_lazy_import_pkg_cross_import(self):
27902790

27912791
g = test.test_import.data.lazy_imports.pkg.c.get_globals()
27922792
self.assertEqual(type(g["x"]), int)
2793-
self.assertEqual(type(g["b"]), importlib.lazy_import)
2793+
self.assertEqual(type(g["b"]), types.LazyImportType)
27942794

27952795
class TestSinglePhaseSnapshot(ModuleSnapshot):
27962796
"""A representation of a single-phase init module for testing.

Modules/_typesmodule.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "Python.h"
44
#include "pycore_descrobject.h" // _PyMethodWrapper_Type
5+
#include "pycore_lazyimportobject.h" // PyLazyImport_Type
56
#include "pycore_namespace.h" // _PyNamespace_Type
67
#include "pycore_object.h" // _PyNone_Type, _PyNotImplemented_Type
78
#include "pycore_unionobject.h" // _PyUnion_Type
@@ -35,6 +36,7 @@ _types_exec(PyObject *m)
3536
EXPORT_STATIC_TYPE("GetSetDescriptorType", PyGetSetDescr_Type);
3637
// LambdaType is the same as FunctionType
3738
EXPORT_STATIC_TYPE("LambdaType", PyFunction_Type);
39+
EXPORT_STATIC_TYPE("LazyImportType", PyLazyImport_Type);
3840
EXPORT_STATIC_TYPE("MappingProxyType", PyDictProxy_Type);
3941
EXPORT_STATIC_TYPE("MemberDescriptorType", PyMemberDescr_Type);
4042
EXPORT_STATIC_TYPE("MethodDescriptorType", PyMethodDescr_Type);

Objects/lazyimportobject.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ static PyMethodDef lazy_methods[] = {
144144

145145
PyTypeObject PyLazyImport_Type = {
146146
PyVarObject_HEAD_INIT(&PyType_Type, 0)
147-
"lazy_import", /* tp_name */
148-
sizeof(PyLazyImportObject), /* tp_basicsize */
147+
"LazyImport", /* tp_name */
148+
sizeof(PyLazyImportObject), /* tp_basicsize */
149149
0, /* tp_itemsize */
150150
(destructor)lazy_import_dealloc, /* tp_dealloc */
151151
0, /* tp_print */

Python/import.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5377,11 +5377,6 @@ imp_module_exec(PyObject *module)
53775377
return -1;
53785378
}
53795379

5380-
if (PyModule_AddObjectRef(module, "lazy_import",
5381-
(PyObject *)&PyLazyImport_Type) < 0) {
5382-
return -1;
5383-
}
5384-
53855380
return 0;
53865381
}
53875382

0 commit comments

Comments
 (0)