[pypy-commit] pypy cpyext-add_newdoc: test for modifying tp_doc even after PyType_Ready
mattip
pypy.commits at gmail.com
Tue Jul 4 15:55:41 EDT 2017
Author: Matti Picus <matti.picus at gmail.com>
Branch: cpyext-add_newdoc
Changeset: r91679:feb0a7a8e0bb
Date: 2017-07-03 07:58 -0400
http://bitbucket.org/pypy/pypy/changeset/feb0a7a8e0bb/
Log: test for modifying tp_doc even after PyType_Ready
diff --git a/pypy/module/cpyext/test/test_typeobject.py b/pypy/module/cpyext/test/test_typeobject.py
--- a/pypy/module/cpyext/test/test_typeobject.py
+++ b/pypy/module/cpyext/test/test_typeobject.py
@@ -1347,3 +1347,34 @@
Bsize = module.get_basicsize(B)
assert Asize == Bsize
assert Asize > basesize
+
+ def test_late_doc_setup(self):
+ module = self.import_extension('foo', [
+ ("getType", "METH_NOARGS",
+ '''
+ Py_INCREF(&FooType_Type);
+ return (PyObject *)&FooType_Type;
+ '''
+ ),
+ ("add_doc_string", "METH_O",
+ '''
+ PyTypeObject* obj = (PyTypeObject *)args;
+ obj->tp_doc = "A docstring";
+ Py_INCREF(Py_None);
+ return Py_None;
+ '''
+ )], prologue='''
+ static PyTypeObject FooType_Type = {
+ PyVarObject_HEAD_INIT(NULL, 0)
+ "foo.Type",
+ };
+ ''', more_init='''
+ FooType_Type.tp_flags = Py_TPFLAGS_DEFAULT;
+ FooType_Type.tp_base = &PyType_Type;
+ if (PyType_Ready(&FooType_Type) < 0) INITERROR;
+ ''')
+ a = module.getType()
+ module.add_doc_string(a)
+ assert a.__doc__ == "A docstring"
+ assert a.__dict__['__doc__'] == None # compatibility
+
More information about the pypy-commit
mailing list