Show More
@@ -53,6 +53,26 b' else:' | |||
|
53 | 53 | # The main DisplayFormatter class |
|
54 | 54 | #----------------------------------------------------------------------------- |
|
55 | 55 | |
|
56 | ||
|
57 | def _valid_formatter(f): | |
|
58 | """Return whether an object is a valid formatter | |
|
59 | ||
|
60 | Cases checked: | |
|
61 | ||
|
62 | - bound methods OK | |
|
63 | - unbound methods NO | |
|
64 | - any other callable OK | |
|
65 | """ | |
|
66 | if isinstance(f, types.MethodType): | |
|
67 | # bound methods are okay, unbound are not | |
|
68 | return f.__self__ is not None | |
|
69 | elif isinstance(f, type(str.find)): | |
|
70 | # unbound methods on compiled classes have type method_descriptor | |
|
71 | return False | |
|
72 | elif callable(f): | |
|
73 | return True | |
|
74 | return False | |
|
75 | ||
|
56 | 76 | class DisplayFormatter(Configurable): |
|
57 | 77 | |
|
58 | 78 | # When set to true only the default plain text formatter will be used. |
@@ -314,7 +334,7 b' class BaseFormatter(Configurable):' | |||
|
314 | 334 | # Finally look for special method names |
|
315 | 335 | method = pretty._safe_getattr(obj, self.print_method, None) |
|
316 | 336 | # print_method must be a bound method: |
|
317 | if isinstance(method, types.MethodType) and method.__self__ is not None: | |
|
337 | if _valid_formatter(method): | |
|
318 | 338 | return method() |
|
319 | 339 | return None |
|
320 | 340 | else: |
General Comments 0
You need to be logged in to leave comments.
Login now