[issue20438] inspect: Deprecate getfullargspec?
Nick Coghlan
report at bugs.python.org
Thu Dec 1 08:20:28 EST 2016
Nick Coghlan added the comment:
Noting for the record, as the general way of querying an unbound method for the name of the first parameter and adding it to the bound arguments:
def add_instance_arg(callable, bound_args):
try:
self = callable.__self__
func = callable.__func__
except AttributeError:
return # Not a bound method
unbound_sig = inspect.signature(func)
for name in unbound_sig.parameters:
bound_args.arguments[name] = self
break
>>> method = C().method
>>> sig = inspect.signature(method)
>>> sig
<Signature (arg)>
>>> args = sig.bind(1)
>>> args
<BoundArguments (arg=1)>
>>> add_instance_arg(method, args)
>>> args
<BoundArguments (arg=1, self=<__main__.C object at 0x7f07ab719668>)>
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue20438>
_______________________________________
More information about the Python-bugs-list
mailing list