Author: Matti Picus <[email protected]>
Branch: issue2446
Changeset: r88915:66f21f2d6751
Date: 2016-12-06 20:09 +0200
http://bitbucket.org/pypy/pypy/changeset/66f21f2d6751/

Log:    test for issue #2446 (confirmed), issue #2445 (not confirmed), "fix"
        for #2446

diff --git a/pypy/module/cpyext/pyobject.py b/pypy/module/cpyext/pyobject.py
--- a/pypy/module/cpyext/pyobject.py
+++ b/pypy/module/cpyext/pyobject.py
@@ -77,6 +77,11 @@
                             "from a PyObject",
                             w_type)
             raise
+        # XXX Assign some attributes of the w_type to the w_obj,
+        #     i.e. w_type.w_doc => w_obj.__doc__
+        #     are there more?
+        if w_type.w_doc:
+            space.setattr(w_obj, space.wrap('__doc__'), w_type.w_doc)
         track_reference(space, obj, w_obj)
         return w_obj
 
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
@@ -142,7 +142,7 @@
         assert fuu2(u"abc").baz().escape()
         raises(TypeError, module.fooType.object_member.__get__, 1)
 
-    def test_multiple_inheritance(self):
+    def test_multiple_inheritance1(self):
         module = self.import_module(name='foo')
         obj = module.UnicodeSubtype(u'xyz')
         obj2 = module.UnicodeSubtype2()
@@ -422,7 +422,7 @@
         assert space.int_w(space.getattr(w_class, w_name)) == 1
         space.delitem(w_dict, w_name)
 
-    def test_multiple_inheritance(self, space, api):
+    def test_multiple_inheritance2(self, space, api):
         w_class = space.appexec([], """():
             class A(object):
                 pass
@@ -1167,3 +1167,43 @@
             __metaclass__ = FooType
         print repr(X)
         X()
+
+    def test_multiple_inheritance3(self):
+        module = self.import_extension('foo', [
+           ("new_obj", "METH_NOARGS",
+            '''
+                PyObject *obj;
+                obj = PyObject_New(PyObject, &Foo12_Type);
+                return obj;
+            '''
+            )], prologue='''
+            static PyTypeObject Foo1_Type = {
+                PyVarObject_HEAD_INIT(NULL, 0)
+                "foo.foo1",
+            };
+            static PyTypeObject Foo2_Type = {
+                PyVarObject_HEAD_INIT(NULL, 0)
+                "foo.foo2",
+            };
+            static PyTypeObject Foo12_Type = {
+                PyVarObject_HEAD_INIT(NULL, 0)
+                "foo.foo12",
+            };
+            static char doc[]="The foo12 object";
+            ''', more_init = '''
+                Foo1_Type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
+                Foo2_Type.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
+                Foo12_Type.tp_flags = Py_TPFLAGS_DEFAULT;
+                Foo12_Type.tp_base = &Foo1_Type;
+                Foo12_Type.tp_doc = doc;
+                Foo12_Type.tp_bases = PyTuple_Pack(2, &Foo1_Type, &Foo2_Type);
+                if (PyType_Ready(&Foo1_Type) < 0) INITERROR;
+                if (PyType_Ready(&Foo2_Type) < 0) INITERROR;
+                if (PyType_Ready(&Foo12_Type) < 0) INITERROR;
+            ''')
+        obj = module.new_obj()
+        assert 'foo.foo12' in str(obj)
+        assert type(obj).__doc__ == "The foo12 object"
+        assert obj.__doc__ == "The foo12 object"
+
+
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to