|
1 | | -/* Copyright (c) Meta, Inc. and its affiliates. All Rights Reserved */ |
2 | | -/* File added for Lazy Imports */ |
3 | | - |
4 | 1 | /* Lazy object implementation */ |
5 | 2 |
|
6 | 3 | #include "Python.h" |
@@ -86,6 +83,24 @@ lazy_import_clear(PyLazyImportObject *m) |
86 | 83 | return 0; |
87 | 84 | } |
88 | 85 |
|
| 86 | +static PyObject * |
| 87 | +lazy_import_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
| 88 | +{ |
| 89 | + if (PyTuple_GET_SIZE(args) != 2 && PyTuple_GET_SIZE(args) != 3) { |
| 90 | + PyErr_SetString(PyExc_ValueError, "lazy_import expected 2-3 arguments"); |
| 91 | + return NULL; |
| 92 | + } |
| 93 | + |
| 94 | + PyObject *builtins = PyTuple_GET_ITEM(args, 0); |
| 95 | + PyObject *from = PyTuple_GET_ITEM(args, 1); |
| 96 | + PyObject *attr = NULL; |
| 97 | + if (PyTuple_GET_SIZE(args) == 3) { |
| 98 | + attr = PyTuple_GET_ITEM(args, 2); |
| 99 | + } |
| 100 | + |
| 101 | + return _PyLazyImport_New(builtins, from, attr); |
| 102 | +} |
| 103 | + |
89 | 104 | PyObject * |
90 | 105 | _PyLazyImport_GetName(PyObject *lazy_import) |
91 | 106 | { |
@@ -132,6 +147,6 @@ PyTypeObject PyLazyImport_Type = { |
132 | 147 | 0, /* tp_dictoffset */ |
133 | 148 | 0, /* tp_init */ |
134 | 149 | PyType_GenericAlloc, /* tp_alloc */ |
135 | | - PyType_GenericNew, /* tp_new */ |
| 150 | + lazy_import_new, /* tp_new */ |
136 | 151 | PyObject_GC_Del, /* tp_free */ |
137 | 152 | }; |
0 commit comments