all Python 3deprecated in 3.5inspectfunction
inspect.getcallargs()
signatures
Deprecated since 3.5: maps arguments to parameter names as a real call would and returns a dict. Use Signature.bind() instead.
Syntax
inspect.getcallargs(func, /, *args, **kwds)
The deprecation exists only in the docs: no warning is emitted and the function still works in every 3.x, so it lingers in older code. Unlike bind() it fills in defaults, empty *args and **kwargs right away and adds self for a bound method; a bad call raises the same TypeError a real call would. New code uses signature(f).bind(...) with apply_defaults().
Examples
import inspect
def g(a, b=1, *args, **kw): pass
print(inspect.getcallargs(g, 1)) # → {'a': 1, 'args': (), 'kw': {}, 'b': 1}
ba = inspect.signature(g).bind(1)
ba.apply_defaults()
print(ba.arguments) # → {'a': 1, 'b': 1, 'args': (), 'kw': {}}
try:
inspect.getcallargs(g)
except TypeError as e:
print(e) # → g() missing 1 required positional argument: 'a'
See also
Open in the full glossarydocs.python.orgReport an inaccuracy