##// END OF EJS Templates
add _valid_formatter...
MinRK -
Show More
@@ -53,6 +53,26 b' else:'
53 # The main DisplayFormatter class
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 class DisplayFormatter(Configurable):
76 class DisplayFormatter(Configurable):
57
77
58 # When set to true only the default plain text formatter will be used.
78 # When set to true only the default plain text formatter will be used.
@@ -314,7 +334,7 b' class BaseFormatter(Configurable):'
314 # Finally look for special method names
334 # Finally look for special method names
315 method = pretty._safe_getattr(obj, self.print_method, None)
335 method = pretty._safe_getattr(obj, self.print_method, None)
316 # print_method must be a bound method:
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 return method()
338 return method()
319 return None
339 return None
320 else:
340 else:
General Comments 0
You need to be logged in to leave comments. Login now