[New-bugs-announce] [issue3135] inspect.getcallargs()

George Sakkis report at bugs.python.org
Thu Jun 19 00:16:54 CEST 2008

New submission from George Sakkis <george.sakkis at gmail.com>:

I'd like to propose a new function for inclusion to the inspect module
-- getcallargs(func, *args, **kwds) -- that returns a dict which maps
the formal arguments of a function (or other callable) to the values
passed as args and kwds, just as Python has to do when calling
func(*args, **kwds). For example:

>>> def func(a, b='foo', c=None, *x, **y):
...         pass
>>> sorted(getcallargs(func, 5, z=3, b=2).items())
 [('a', 5), ('b', 2), ('c', None), ('x', ()), ('y', {'z': 3})]

This is handy when writing decorators, or more generally when one would
want to do some minimal type checking without actually calling the function.

I have posted a recipe at
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/551779; I can
clean it up and submit a proper patch if it's deemed useful enough for
the stdlib.

components: Library (Lib)
messages: 68378
nosy: gsakkis
severity: normal
status: open
title: inspect.getcallargs()
type: feature request
versions: Python 2.6

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list