[pypy-commit] pypy default: super.__repr__
arigo
pypy.commits at gmail.com
Tue Aug 30 07:31:00 EDT 2016
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r86730:93745a358dcc
Date: 2016-08-30 13:30 +0200
http://bitbucket.org/pypy/pypy/changeset/93745a358dcc/
Log: super.__repr__
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
@@ -23,6 +23,14 @@
self.w_objtype = w_type
self.w_self = w_obj_or_type
+ def descr_repr(self, space):
+ if self.w_objtype is not None:
+ objtype_name = "<%s object>" % self.w_objtype.getname(space)
+ else:
+ objtype_name = 'NULL'
+ return space.wrap("<super: <class '%s'>, %s>" % (
+ self.w_starttype.getname(space), objtype_name))
+
def get(self, space, w_obj, w_type=None):
if self.w_self is None or space.is_w(w_obj, space.w_None):
return self
@@ -84,6 +92,7 @@
'super',
__new__ = generic_new_descr(W_Super),
__init__ = interp2app(W_Super.descr_init),
+ __repr__ = interp2app(W_Super.descr_repr),
__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),
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
@@ -261,6 +261,13 @@
assert super(A, b).__self_class__ is B
assert super(A).__self_class__ is None
+ def test_super_repr(self):
+ class A(object):
+ def __repr__(self):
+ return super(A, self).__repr__() + '!'
+ assert repr(A()).endswith('>!')
+ assert repr(super(A, A())) == "<super: <class 'A'>, <A object>>"
+
def test_property_docstring(self):
assert property.__doc__.startswith('property')
More information about the pypy-commit
mailing list