From cf19c83fac38cc9f8ea7484c697b29846569f7b7 2014-11-15 00:49:23 From: Thomas Kluyver Date: 2014-11-15 00:49:23 Subject: [PATCH] Merge pull request #6932 from takluyver/help-signatures Better support for wrapped function signatures in help --- diff --git a/IPython/core/oinspect.py b/IPython/core/oinspect.py index 68adadb..6e6b31b 100644 --- a/IPython/core/oinspect.py +++ b/IPython/core/oinspect.py @@ -40,6 +40,7 @@ from IPython.utils.text import indent from IPython.utils.wildcard import list_namespace from IPython.utils.coloransi import TermColors, ColorScheme, ColorSchemeTable from IPython.utils.py3compat import cast_unicode, string_types, PY3 +from IPython.utils.signatures import signature # builtin docstrings to ignore _func_call_docstring = types.FunctionType.__call__.__doc__ @@ -390,7 +391,7 @@ class Inspector: If any exception is generated, None is returned instead and the exception is suppressed.""" try: - hdef = oname + inspect.formatargspec(*getargspec(obj)) + hdef = oname + str(signature(obj)) return cast_unicode(hdef) except: return None 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__