summaryrefslogtreecommitdiffstats
path: root/Doc/library/inspect.rst
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2010-03-30 18:42:32 (GMT)
committerBenjamin Peterson <benjamin@python.org>2010-03-30 18:42:32 (GMT)
commit25cd7eb9a14cb646e58e315ebfafe867862a705b (patch)
tree79a7b79ca21a2f2e8e3012163745f9d513edbeaf /Doc/library/inspect.rst
parente6c9d24562adf4eddfcbeb6cc1873b3e6795e2eb (diff)
downloadcpython-25cd7eb9a14cb646e58e315ebfafe867862a705b.zip
cpython-25cd7eb9a14cb646e58e315ebfafe867862a705b.tar.gz
cpython-25cd7eb9a14cb646e58e315ebfafe867862a705b.tar.bz2
Merged revisions 79500 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r79500 | benjamin.peterson | 2010-03-30 12:58:13 -0500 (Tue, 30 Mar 2010) | 4 lines add inspect.getcallargs, which binds function arguments like a normal call #3135 Patch by George Sakkis ........
Diffstat (limited to 'Doc/library/inspect.rst')
-rw-r--r--Doc/library/inspect.rst26
1 files changed, 26 insertions, 0 deletions
diff --git a/Doc/library/inspect.rst b/Doc/library/inspect.rst
index 5087733..572a401 100644
--- a/Doc/library/inspect.rst
+++ b/Doc/library/inspect.rst
@@ -449,6 +449,32 @@ Classes and functions
metatype is in use, cls will be the first element of the tuple.
+.. function:: getcallargs(func[, *args][, **kwds])
+
+ Bind the *args* and *kwds* to the argument names of the Python function or
+ method *func*, as if it was called with them. For bound methods, bind also the
+ first argument (typically named ``self``) to the associated instance. A dict
+ is returned, mapping the argument names (including the names of the ``*`` and
+ ``**`` arguments, if any) to their values from *args* and *kwds*. In case of
+ invoking *func* incorrectly, i.e. whenever ``func(*args, **kwds)`` would raise
+ an exception because of incompatible signature, an exception of the same type
+ and the same or similar message is raised. For example::
+
+ >>> from inspect import getcallargs
+ >>> def f(a, b=1, *pos, **named):
+ ... pass
+ >>> getcallargs(f, 1, 2, 3)
+ {'a': 1, 'named': {}, 'b': 2, 'pos': (3,)}
+ >>> getcallargs(f, a=2, x=4)
+ {'a': 2, 'named': {'x': 4}, 'b': 1, 'pos': ()}
+ >>> getcallargs(f)
+ Traceback (most recent call last):
+ ...
+ TypeError: f() takes at least 1 argument (0 given)
+
+ .. versionadded:: 3.2
+
+
.. _inspect-stack:
The interpreter stack