##// END OF EJS Templates
rewrite _valid_formatter...
MinRK -
Show More
@@ -25,6 +25,7 b' Authors:'
25
25
26 # Stdlib imports
26 # Stdlib imports
27 import abc
27 import abc
28 import inspect
28 import sys
29 import sys
29 import types
30 import types
30 import warnings
31 import warnings
@@ -59,18 +60,24 b' def _valid_formatter(f):'
59
60
60 Cases checked:
61 Cases checked:
61
62
62 - bound methods OK
63 - bound methods OK
63 - unbound methods NO
64 - unbound methods NO
64 - any other callable OK
65 - callable with zero args OK
65 """
66 """
66 if isinstance(f, types.MethodType):
67 if isinstance(f, type(str.find)):
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
68 # unbound methods on compiled classes have type method_descriptor
71 return False
69 return False
72 elif callable(f):
70 elif isinstance(f, types.BuiltinFunctionType):
71 # bound methods on compiled classes have type builtin_function
73 return True
72 return True
73 elif callable(f):
74 # anything that works with zero args should be okay
75 try:
76 inspect.getcallargs(f)
77 except TypeError:
78 return False
79 else:
80 return True
74 return False
81 return False
75
82
76 class DisplayFormatter(Configurable):
83 class DisplayFormatter(Configurable):
General Comments 0
You need to be logged in to leave comments. Login now