Author: Armin Rigo <[email protected]>
Branch: py3.5
Changeset: r89610:babebbeb4488
Date: 2017-01-16 17:45 +0100
http://bitbucket.org/pypy/pypy/changeset/babebbeb4488/
Log: Fix the __repr__ of bound methods to use the qualname of the
function
diff --git a/pypy/interpreter/function.py b/pypy/interpreter/function.py
--- a/pypy/interpreter/function.py
+++ b/pypy/interpreter/function.py
@@ -535,11 +535,18 @@
def descr_method_repr(self):
space = self.space
- name = self.w_function.getname(self.space)
- w_class = space.type(self.w_instance)
- typename = w_class.getname(self.space)
+ w_name = space.findattr(self.w_function, space.wrap('__qualname__'))
+ if w_name is None:
+ name = self.w_function.getname(self.space)
+ else:
+ try:
+ name = space.unicode_w(w_name)
+ except OperationError as e:
+ if not e.match(space, space.w_TypeError):
+ raise
+ name = '?'
objrepr = space.unicode_w(space.repr(self.w_instance))
- s = u'<bound method %s.%s of %s>' % (typename, name, objrepr)
+ s = u'<bound method %s of %s>' % (name, objrepr)
return space.wrap(s)
def descr_method_getattribute(self, w_attr):
diff --git a/pypy/interpreter/test/test_function.py
b/pypy/interpreter/test/test_function.py
--- a/pypy/interpreter/test/test_function.py
+++ b/pypy/interpreter/test/test_function.py
@@ -516,14 +516,19 @@
class A(object):
def f(self):
pass
- assert repr(A().f).startswith("<bound method A.f of <")
+ assert repr(A().f).startswith("<bound method %s.f of <" %
+ A.__qualname__)
assert repr(A().f).endswith(">>")
- class B:
+
+ def test_method_repr_2(self):
+ class ClsA(object):
def f(self):
pass
- assert repr(B().f).startswith("<bound method B.f of <")
- assert repr(A().f).endswith(">>")
-
+ class ClsB(ClsA):
+ pass
+ r = repr(ClsB().f)
+ assert "ClsA.f of <" in r
+ assert "ClsB object at " in r
def test_method_call(self):
class C(object):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit