|
37 | 37 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
38 | 38 | # SOFTWARE. |
39 | 39 | import sys |
40 | | -from . import CPyExtType, CPyExtHeapType |
| 40 | +from . import CPyExtType, CPyExtHeapType, compile_module_from_string |
41 | 41 |
|
42 | 42 | SlotsGetter = CPyExtType("SlotsGetter", |
43 | 43 | """ |
@@ -245,3 +245,43 @@ class MyClassWithDescr2: |
245 | 245 | # assert SlotsGetter.get_tp_descr_get(HackySlotsWithManaged()) == SlotsGetter.get_tp_attro(ManagedAttrO()) |
246 | 246 | finally: |
247 | 247 | sys.modules.pop("test_incompatible_slots_assignment_managed", None) |
| 248 | + |
| 249 | + |
| 250 | +def test_type_not_ready(): |
| 251 | + module = compile_module_from_string(""" |
| 252 | + #define PY_SSIZE_T_CLEAN |
| 253 | + #include <Python.h> |
| 254 | + |
| 255 | + static PyObject* my_getattro(PyObject* self, PyObject* key) { |
| 256 | + return Py_NewRef(key); |
| 257 | + } |
| 258 | + |
| 259 | + static PyTypeObject NotReadyType = { |
| 260 | + PyVarObject_HEAD_INIT(NULL, 0) |
| 261 | + .tp_name = "NotReadyType", |
| 262 | + .tp_basicsize = sizeof(PyObject), |
| 263 | + .tp_dealloc = (destructor)PyObject_Del, |
| 264 | + .tp_getattro = my_getattro |
| 265 | + }; |
| 266 | + |
| 267 | + static PyObject* create_not_ready(PyObject* module, PyObject* unused) { |
| 268 | + return PyObject_New(PyObject, &NotReadyType); |
| 269 | + } |
| 270 | + |
| 271 | + static PyMethodDef module_methods[] = { |
| 272 | + {"create_not_ready", _PyCFunction_CAST(create_not_ready), METH_NOARGS, ""}, |
| 273 | + {NULL} |
| 274 | + }; |
| 275 | + |
| 276 | + static PyModuleDef NotReadyTypeModule = { |
| 277 | + PyModuleDef_HEAD_INIT, "NotReadyType", "", -1, module_methods |
| 278 | + }; |
| 279 | + |
| 280 | + PyMODINIT_FUNC |
| 281 | + PyInit_NotReadyType(void) |
| 282 | + { |
| 283 | + return PyModule_Create(&NotReadyTypeModule); |
| 284 | + } |
| 285 | + """, "NotReadyType") |
| 286 | + not_ready = module.create_not_ready() |
| 287 | + assert not_ready.foo == 'foo' |
0 commit comments