You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
I updated the recipe to also return a missing_args tuple - the tuple
of the formal parameters whose value was not provided. This is useful in
cases where one want to distinguish f() from f(None) given "def f(x=None)".
I reverted the function to the original API (return just the dict with the bindings), cleaned it up, wrote thorough unit tests and made a patch against Python 2.7a4.
gsakkis commented on Mar 19, 2010
gsakkismannequin
MannequinAuthor
More actions
Renamed the Testcase classes to conform with the rest in test_inspect.py, added a few more tests for tuple args and patched against the latest trunk (r79086).
Applied in r79500. Note I removed the error checking that a bound method received an instance of the class as the first argument because that error checking is a function of the calling of the function, not the binding of the arguments.
Activity
gsakkis commentedon Jun 18, 2008
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:
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.
gsakkis commentedon May 15, 2009
I updated the recipe to also return a
missing_argstuple - the tupleof the formal parameters whose value was not provided. This is useful in
cases where one want to distinguish f() from f(None) given "def f(x=None)".
gsakkis commentedon May 15, 2009
Also updated url: http://code.activestate.com/recipes/551779/
gsakkis commentedon Mar 19, 2010
I reverted the function to the original API (return just the dict with the bindings), cleaned it up, wrote thorough unit tests and made a patch against Python 2.7a4.
gsakkis commentedon Mar 19, 2010
Renamed the Testcase classes to conform with the rest in test_inspect.py, added a few more tests for tuple args and patched against the latest trunk (r79086).
benjaminp commentedon Mar 19, 2010
The patch will also need docs in inspect.rst.
gsakkis commentedon Mar 19, 2010
benjaminp commentedon Mar 19, 2010
Would you upload this patch to Rietveld for review?
gsakkis commentedon Mar 19, 2010
Uploaded at http://codereview.appspot.com/659041/show
benjaminp commentedon Mar 30, 2010
Applied in r79500. Note I removed the error checking that a bound method received an instance of the class as the first argument because that error checking is a function of the calling of the function, not the binding of the arguments.