[pypy-commit] pypy default: Fix: 'tp_descr_get(self, NULL, type)' used to give a real undefined

arigo pypy.commits at gmail.com
Mon Jun 5 05:51:21 EDT 2017


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r91519:07257b27db4b
Date: 2017-06-05 11:25 +0200
http://bitbucket.org/pypy/pypy/changeset/07257b27db4b/

Log:	Fix: 'tp_descr_get(self, NULL, type)' used to give a real undefined
	value for the second argument if implemented in Python

diff --git a/pypy/module/cpyext/test/test_userslots.py b/pypy/module/cpyext/test/test_userslots.py
--- a/pypy/module/cpyext/test/test_userslots.py
+++ b/pypy/module/cpyext/test/test_userslots.py
@@ -51,7 +51,7 @@
         w_descr = space.appexec([], """():
             class Descr(object):
                 def __get__(self, obj, type):
-                    return 42
+                    return 42 + (obj is None)
                 def __set__(self, obj, value):
                     obj.append('set')
                 def __delete__(self, obj):
@@ -73,6 +73,11 @@
             space, py_descrtype.c_tp_descr_set,
             py_descr, py_obj, None) == 0
         assert space.eq_w(w_obj, space.wrap(['set', 'del']))
+        #
+        # unbound __get__(self, NULL, type)
+        w_res = generic_cpy_call(space, py_descrtype.c_tp_descr_get,
+                                 py_descr, None, space.w_int)
+        assert space.int_w(w_res) == 43
 
 class AppTestUserSlots(AppTestCpythonExtensionBase):
     def test_tp_hash_from_python(self):
diff --git a/pypy/module/cpyext/userslot.py b/pypy/module/cpyext/userslot.py
--- a/pypy/module/cpyext/userslot.py
+++ b/pypy/module/cpyext/userslot.py
@@ -111,6 +111,8 @@
 
 @slot_function([PyObject, PyObject, PyObject], PyObject)
 def slot_tp_descr_get(space, w_self, w_obj, w_type):
+    if w_obj is None:
+        w_obj = space.w_None
     return space.get(w_self, w_obj, w_type)
 
 @slot_function([PyObject, PyObject, PyObject], rffi.INT_real, error=-1)


More information about the pypy-commit mailing list