##// END OF EJS Templates
Fix signature with unbound methods
Thomas Kluyver -
Show More
@@ -72,8 +72,11 b' def signature(obj):'
72 raise TypeError('{0!r} is not a callable object'.format(obj))
72 raise TypeError('{0!r} is not a callable object'.format(obj))
73
73
74 if isinstance(obj, types.MethodType):
74 if isinstance(obj, types.MethodType):
75 # In this case we skip the first parameter of the underlying
75 if obj.__self__ is None:
76 # function (usually `self` or `cls`).
76 # Unbound method - treat it as a function (no distinction in Py 3)
77 obj = obj.__func__
78 else:
79 # Bound method: trim off the first parameter (typically self or cls)
77 sig = signature(obj.__func__)
80 sig = signature(obj.__func__)
78 return sig.replace(parameters=tuple(sig.parameters.values())[1:])
81 return sig.replace(parameters=tuple(sig.parameters.values())[1:])
79
82
General Comments 0
You need to be logged in to leave comments. Login now