We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f426c0b commit 2693269Copy full SHA for 2693269
src/_pytest/_io/saferepr.py
@@ -1,5 +1,6 @@
1
import pprint
2
import reprlib
3
+from types import MethodType
4
from typing import Optional
5
6
@@ -58,7 +59,17 @@ def repr(self, x: object) -> str:
58
59
if self.use_ascii:
60
s = ascii(x)
61
else:
- s = super().repr(x)
62
+ if isinstance(x, MethodType):
63
+ # for bound methods, skip redundant <bound method ...> information
64
+ s = x.__name__
65
+ else:
66
+ # if none of the mro classes have implemented __repr__
67
+ # show class name
68
+ mro_classes = x.__class__.mro()[:-1]
69
+ if not any("__repr__" in cls.__dict__ for cls in mro_classes):
70
+ s = x.__class__.__name__
71
72
+ s = super().repr(x)
73
74
except (KeyboardInterrupt, SystemExit):
75
raise
0 commit comments