[pypy-commit] pypy default: Add super.__self__ and super.__self_class__

arigo pypy.commits at gmail.com
Tue Aug 30 07:30:58 EDT 2016


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r86729:04632dd29e04
Date: 2016-08-30 13:26 +0200
http://bitbucket.org/pypy/pypy/changeset/04632dd29e04/

Log:	Add super.__self__ and super.__self_class__

diff --git a/pypy/module/__builtin__/descriptor.py b/pypy/module/__builtin__/descriptor.py
--- a/pypy/module/__builtin__/descriptor.py
+++ b/pypy/module/__builtin__/descriptor.py
@@ -85,6 +85,8 @@
     __new__          = generic_new_descr(W_Super),
     __init__         = interp2app(W_Super.descr_init),
     __thisclass__    = interp_attrproperty_w("w_starttype", W_Super),
+    __self__         = interp_attrproperty_w("w_self", W_Super),
+    __self_class__   = interp_attrproperty_w("w_objtype", W_Super),
     __getattribute__ = interp2app(W_Super.getattribute),
     __get__          = interp2app(W_Super.get),
     __doc__          =     """\
diff --git a/pypy/module/__builtin__/test/test_descriptor.py b/pypy/module/__builtin__/test/test_descriptor.py
--- a/pypy/module/__builtin__/test/test_descriptor.py
+++ b/pypy/module/__builtin__/test/test_descriptor.py
@@ -250,6 +250,17 @@
         assert super(B, B()).__thisclass__ is B
         assert super(A, B()).__thisclass__ is A
 
+    def test_super_self_selfclass(self):
+        class A(object):
+            pass
+        class B(A):
+            pass
+        b = B()
+        assert super(A, b).__self__ is b
+        assert super(A).__self__ is None
+        assert super(A, b).__self_class__ is B
+        assert super(A).__self_class__ is None
+
     def test_property_docstring(self):
         assert property.__doc__.startswith('property')
 


More information about the pypy-commit mailing list