Directly calling python's function arguments dispatcher

Peter Otten __peter__ at web.de
Sun Dec 12 17:41:47 EST 2010


Pascal Chambon wrote:


> I've encountered several times, when dealing with adaptation of function
> signatures, the need for explicitly resolving complex argument sets into
> a simple variable mapping. Explanations.
> 
> 
> Consider that function:
> 
> def foo(a1, a2, *args, **kwargs):
>      pass
> 
> calling foo(1, a2=2, a3=3)
> 
> will map these arguments to local variables like these:
> {
> 'a1': 1,
> 'a2': 2,
> 'args': tuple(),
> 'kwarg's: {'a3': 3}
> }
> 
> That's a quite complex resolution mechanism, which must handle
> positional and keyword arguments, and deal with both collision and
> missing argument cases.

> Is that routine exposed to python, somewhere ? Does anybody know a
> working implementation here or there ?

http://docs.python.org/library/inspect.html#inspect.getcallargs




More information about the Python-list mailing list