[pypy-commit] pypy py3.6: issue #3055

arigo pypy.commits at gmail.com
Fri Aug 16 06:02:00 EDT 2019


Author: Armin Rigo <arigo at tunes.org>
Branch: py3.6
Changeset: r97197:72fdf69a0e6d
Date: 2019-08-16 12:01 +0200
http://bitbucket.org/pypy/pypy/changeset/72fdf69a0e6d/

Log:	issue #3055

	fix if we see a PyTypeObject with tp_doc==""

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
@@ -1624,6 +1624,28 @@
         assert module.get_number() == 4043
         raises(AttributeError, "del foo.bar")
 
+    def test_tp_doc_issue3055(self):
+        module = self.import_extension('foo', [
+           ("new_obj", "METH_NOARGS",
+            '''
+                PyObject *obj;
+                obj = PyObject_New(PyObject, &Foo_Type);
+                return obj;
+            '''
+            )], prologue='''
+            static PyTypeObject Foo_Type = {
+                PyVarObject_HEAD_INIT(NULL, 0)
+                "foo.foo",
+                sizeof(PyObject),
+            };
+            ''', more_init = '''
+                Foo_Type.tp_flags = Py_TPFLAGS_DEFAULT;
+                Foo_Type.tp_doc = "";
+                if (PyType_Ready(&Foo_Type) < 0) INITERROR;
+            ''')
+        obj = module.new_obj()
+        assert type(obj).__doc__ is None
+
 
 class AppTestHashable(AppTestCpythonExtensionBase):
     def test_unhashable(self):
diff --git a/pypy/module/cpyext/typeobject.py b/pypy/module/cpyext/typeobject.py
--- a/pypy/module/cpyext/typeobject.py
+++ b/pypy/module/cpyext/typeobject.py
@@ -381,7 +381,7 @@
         dict_w[method_name] = w_obj
     if pto.c_tp_doc:
         raw_doc = rffi.charp2str(cts.cast('char*', pto.c_tp_doc))
-        dict_w['__doc__'] = space.newtext(extract_doc(raw_doc, name))
+        dict_w['__doc__'] = space.newtext_or_none(extract_doc(raw_doc, name))
     if pto.c_tp_new:
         add_tp_new_wrapper(space, dict_w, pto)
 


More information about the pypy-commit mailing list