@@ -183,21 +183,43 @@ def test_repr(self):
183
183
def test_base_type (self ):
184
184
AcceptableBaseType = CPyExtType ("AcceptableBaseType" ,
185
185
'''
186
+ static PyObject *
187
+ TestBase_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
188
+ {
189
+ return PyType_Type.tp_new(type, args, kwds);
190
+ }
186
191
PyTypeObject TestBase_Type = {
187
192
PyVarObject_HEAD_INIT(NULL, 0)
188
- .tp_name = "AcceptableBaseType ",
193
+ .tp_name = "TestBase ",
189
194
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
190
195
};
196
+
197
+ static int
198
+ AcceptableBaseType_traverse(AcceptableBaseTypeObject *self, visitproc visit, void *arg) {
199
+ // This helps to avoid setting 'Py_TPFLAGS_HAVE_GC'
200
+ // see typeobject.c:inherit_special:241
201
+ return 0;
202
+ }
203
+
204
+ static int
205
+ AcceptableBaseType_clear(AcceptableBaseTypeObject *self) {
206
+ // This helps to avoid setting 'Py_TPFLAGS_HAVE_GC'
207
+ // see typeobject.c:inherit_special:241
208
+ return 0;
209
+ }
191
210
''' ,
211
+ tp_traverse = "(traverseproc)AcceptableBaseType_traverse" ,
212
+ tp_clear = "(inquiry)AcceptableBaseType_clear" ,
192
213
ready_code = '''
193
- TestBase_Type.tp_base = &PyType_Type;
194
- if (PyType_Ready(&TestBase_Type) < 0)
195
- return NULL;
196
- Py_TYPE(&AcceptableBaseTypeType) = &TestBase_Type;
197
- AcceptableBaseTypeType.tp_base = &PyType_Type;
198
- ''' ,
214
+ TestBase_Type.tp_base = &PyType_Type;
215
+ if (PyType_Ready(&TestBase_Type) < 0)
216
+ return NULL;
217
+
218
+ Py_TYPE(& AcceptableBaseTypeType) = &TestBase_Type;
219
+ AcceptableBaseTypeType.tp_base = &PyType_Type; ''' ,
199
220
)
200
- class AcceptableSubClass (AcceptableBaseType ):
221
+ class Foo (AcceptableBaseType ):
222
+ # This shouldn't fail
201
223
pass
202
224
203
225
def test_new (self ):
0 commit comments