summaryrefslogtreecommitdiff
path: root/funcsigs/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'funcsigs/__init__.py')
-rw-r--r--funcsigs/__init__.py16
1 files changed, 13 insertions, 3 deletions
diff --git a/funcsigs/__init__.py b/funcsigs/__init__.py
index b9ba326..7dbe0dc 100644
--- a/funcsigs/__init__.py
+++ b/funcsigs/__init__.py
@@ -59,10 +59,20 @@ 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: the first parameter becomes positional-only
+ if sig.parameters:
+ first = sig.parameters.values()[0].replace(
+ kind=_POSITIONAL_ONLY)
+ return sig.replace(parameters=itertools.chain(
+ (first,), tuple(sig.parameters.values())[1:]))
+ else:
+ return sig
+ else:
+ # In this case we skip the first parameter of the underlying
+ # function (usually `self` or `cls`).
+ return sig.replace(parameters=tuple(sig.parameters.values())[1:])
try:
sig = obj.__signature__