New submission from George Sakkis <[EMAIL PROTECTED]>:

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 <[EMAIL PROTECTED]>
<http://bugs.python.org/issue3135>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to