From 88c105a5bd69995b6f007f04532677aa83b0aa97 2014-11-14 01:12:11 From: Thomas Kluyver Date: 2014-11-14 01:12:11 Subject: [PATCH] Fix signature with unbound methods --- diff --git a/IPython/utils/signatures.py b/IPython/utils/signatures.py index 0ab0a88..771899e 100644 --- a/IPython/utils/signatures.py +++ b/IPython/utils/signatures.py @@ -72,10 +72,13 @@ def signature(obj): raise TypeError('{0!r} is not a callable object'.format(obj)) if isinstance(obj, types.MethodType): - # In this case we skip the first parameter of the underlying - # function (usually `self` or `cls`). - sig = signature(obj.__func__) - return sig.replace(parameters=tuple(sig.parameters.values())[1:]) + if obj.__self__ is None: + # Unbound method - treat it as a function (no distinction in Py 3) + obj = obj.__func__ + else: + # Bound method: trim off the first parameter (typically self or cls) + sig = signature(obj.__func__) + return sig.replace(parameters=tuple(sig.parameters.values())[1:]) try: sig = obj.__signature__