mirror of
https://github.com/python/cpython.git
synced 2025-12-08 06:10:17 +00:00
Expose LazyImportType in types module
This commit is contained in:
parent
46b3b75a3a
commit
c5efb20d48
5 changed files with 6 additions and 9 deletions
|
|
@ -59,7 +59,7 @@
|
||||||
|
|
||||||
from ._bootstrap import __import__
|
from ._bootstrap import __import__
|
||||||
|
|
||||||
from _imp import lazy_import, set_lazy_imports
|
from _imp import set_lazy_imports
|
||||||
|
|
||||||
|
|
||||||
def invalidate_caches():
|
def invalidate_caches():
|
||||||
|
|
|
||||||
|
|
@ -2790,7 +2790,7 @@ def test_lazy_import_pkg_cross_import(self):
|
||||||
|
|
||||||
g = test.test_import.data.lazy_imports.pkg.c.get_globals()
|
g = test.test_import.data.lazy_imports.pkg.c.get_globals()
|
||||||
self.assertEqual(type(g["x"]), int)
|
self.assertEqual(type(g["x"]), int)
|
||||||
self.assertEqual(type(g["b"]), importlib.lazy_import)
|
self.assertEqual(type(g["b"]), types.LazyImportType)
|
||||||
|
|
||||||
class TestSinglePhaseSnapshot(ModuleSnapshot):
|
class TestSinglePhaseSnapshot(ModuleSnapshot):
|
||||||
"""A representation of a single-phase init module for testing.
|
"""A representation of a single-phase init module for testing.
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include "Python.h"
|
#include "Python.h"
|
||||||
#include "pycore_descrobject.h" // _PyMethodWrapper_Type
|
#include "pycore_descrobject.h" // _PyMethodWrapper_Type
|
||||||
|
#include "pycore_lazyimportobject.h" // PyLazyImport_Type
|
||||||
#include "pycore_namespace.h" // _PyNamespace_Type
|
#include "pycore_namespace.h" // _PyNamespace_Type
|
||||||
#include "pycore_object.h" // _PyNone_Type, _PyNotImplemented_Type
|
#include "pycore_object.h" // _PyNone_Type, _PyNotImplemented_Type
|
||||||
#include "pycore_unionobject.h" // _PyUnion_Type
|
#include "pycore_unionobject.h" // _PyUnion_Type
|
||||||
|
|
@ -35,6 +36,7 @@ _types_exec(PyObject *m)
|
||||||
EXPORT_STATIC_TYPE("GetSetDescriptorType", PyGetSetDescr_Type);
|
EXPORT_STATIC_TYPE("GetSetDescriptorType", PyGetSetDescr_Type);
|
||||||
// LambdaType is the same as FunctionType
|
// LambdaType is the same as FunctionType
|
||||||
EXPORT_STATIC_TYPE("LambdaType", PyFunction_Type);
|
EXPORT_STATIC_TYPE("LambdaType", PyFunction_Type);
|
||||||
|
EXPORT_STATIC_TYPE("LazyImportType", PyLazyImport_Type);
|
||||||
EXPORT_STATIC_TYPE("MappingProxyType", PyDictProxy_Type);
|
EXPORT_STATIC_TYPE("MappingProxyType", PyDictProxy_Type);
|
||||||
EXPORT_STATIC_TYPE("MemberDescriptorType", PyMemberDescr_Type);
|
EXPORT_STATIC_TYPE("MemberDescriptorType", PyMemberDescr_Type);
|
||||||
EXPORT_STATIC_TYPE("MethodDescriptorType", PyMethodDescr_Type);
|
EXPORT_STATIC_TYPE("MethodDescriptorType", PyMethodDescr_Type);
|
||||||
|
|
|
||||||
|
|
@ -144,8 +144,8 @@ static PyMethodDef lazy_methods[] = {
|
||||||
|
|
||||||
PyTypeObject PyLazyImport_Type = {
|
PyTypeObject PyLazyImport_Type = {
|
||||||
PyVarObject_HEAD_INIT(&PyType_Type, 0)
|
PyVarObject_HEAD_INIT(&PyType_Type, 0)
|
||||||
"lazy_import", /* tp_name */
|
"LazyImport", /* tp_name */
|
||||||
sizeof(PyLazyImportObject), /* tp_basicsize */
|
sizeof(PyLazyImportObject), /* tp_basicsize */
|
||||||
0, /* tp_itemsize */
|
0, /* tp_itemsize */
|
||||||
(destructor)lazy_import_dealloc, /* tp_dealloc */
|
(destructor)lazy_import_dealloc, /* tp_dealloc */
|
||||||
0, /* tp_print */
|
0, /* tp_print */
|
||||||
|
|
|
||||||
|
|
@ -5377,11 +5377,6 @@ imp_module_exec(PyObject *module)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PyModule_AddObjectRef(module, "lazy_import",
|
|
||||||
(PyObject *)&PyLazyImport_Type) < 0) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue