From 3a67ed975d5f825fce703fbf0c42e980a505127c Mon Sep 17 00:00:00 2001 From: Nice Zombies Date: Sun, 2 Jun 2024 08:11:39 +0200 Subject: [PATCH 1/4] Clarify inspect signature bound arguments --- Doc/library/inspect.rst | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/Doc/library/inspect.rst b/Doc/library/inspect.rst index 7130faa4b5b696..6382e4ca0b4d34 100644 --- a/Doc/library/inspect.rst +++ b/Doc/library/inspect.rst @@ -995,12 +995,32 @@ function. .. attribute:: BoundArguments.args A tuple of positional arguments values. Dynamically computed from the - :attr:`arguments` attribute. + :attr:`arguments` attribute. Includes ambiguous arguments (See Note). .. attribute:: BoundArguments.kwargs A dict of keyword arguments values. Dynamically computed from the - :attr:`arguments` attribute. + :attr:`arguments` attribute. Includes ambiguous arguments (See Note). + + .. note:: + + The allocation in :attr:`args` and :attr:`kwargs` may not match the + inserted *args* and *kwargs* in :meth:`Signature.bind` or + :meth:`Signature.bind_partial`. This concerns argument of the kind + *POSITIONAL_OR_KEYWORD* in cases where they can be passed ambiguous + as args or kwargs. In cases of ambiguity the dynamically computation + of args and kwargs always simplifies the given arguments as much as + possible, by dropping keywords and saving them positional in args. + For example:: + + >>> def test(a=1, b=2, c=3): + ... pass + ... + >>> boundargs = signature(test).bind(a=10, c=13) + >>> boundargs.args + (10,) + >>> boundargs.kwargs + {'c': 13} .. attribute:: BoundArguments.signature From bf29f747af4467efb2c01351cf1a69f47b8b95a1 Mon Sep 17 00:00:00 2001 From: Nice Zombies Date: Sun, 2 Jun 2024 08:13:47 +0200 Subject: [PATCH 2/4] Remove trailing space --- Doc/library/inspect.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/inspect.rst b/Doc/library/inspect.rst index 6382e4ca0b4d34..f43bf6069bf1b2 100644 --- a/Doc/library/inspect.rst +++ b/Doc/library/inspect.rst @@ -1015,7 +1015,7 @@ function. >>> def test(a=1, b=2, c=3): ... pass - ... + ... >>> boundargs = signature(test).bind(a=10, c=13) >>> boundargs.args (10,) From d29ef28444b5f6f50ec073a962bd51065e9d020a Mon Sep 17 00:00:00 2001 From: Nice Zombies Date: Sun, 2 Jun 2024 08:48:03 +0200 Subject: [PATCH 3/4] Fix grammar --- Doc/library/inspect.rst | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Doc/library/inspect.rst b/Doc/library/inspect.rst index f43bf6069bf1b2..c42cefd60d0f1e 100644 --- a/Doc/library/inspect.rst +++ b/Doc/library/inspect.rst @@ -1006,11 +1006,11 @@ function. The allocation in :attr:`args` and :attr:`kwargs` may not match the inserted *args* and *kwargs* in :meth:`Signature.bind` or - :meth:`Signature.bind_partial`. This concerns argument of the kind - *POSITIONAL_OR_KEYWORD* in cases where they can be passed ambiguous - as args or kwargs. In cases of ambiguity the dynamically computation - of args and kwargs always simplifies the given arguments as much as - possible, by dropping keywords and saving them positional in args. + :meth:`Signature.bind_partial`. This concerns arguments of the kind + *POSITIONAL_OR_KEYWORD* in cases where they can be passed ambiguously + as args or kwargs. In cases of ambiguity the dynamic computation of + args and kwargs always simplifies the given arguments as much as + possible, by dropping keywords and saving them positionally in args. For example:: >>> def test(a=1, b=2, c=3): From 5c89e59c3ffe20bded029b8f6f33f7b77900676e Mon Sep 17 00:00:00 2001 From: Nineteendo Date: Tue, 10 Sep 2024 13:16:10 +0200 Subject: [PATCH 4/4] Simplify explanation --- Doc/library/inspect.rst | 25 +++---------------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/Doc/library/inspect.rst b/Doc/library/inspect.rst index c42cefd60d0f1e..555eed4bda5c21 100644 --- a/Doc/library/inspect.rst +++ b/Doc/library/inspect.rst @@ -995,32 +995,13 @@ function. .. attribute:: BoundArguments.args A tuple of positional arguments values. Dynamically computed from the - :attr:`arguments` attribute. Includes ambiguous arguments (See Note). + :attr:`arguments` attribute. .. attribute:: BoundArguments.kwargs A dict of keyword arguments values. Dynamically computed from the - :attr:`arguments` attribute. Includes ambiguous arguments (See Note). - - .. note:: - - The allocation in :attr:`args` and :attr:`kwargs` may not match the - inserted *args* and *kwargs* in :meth:`Signature.bind` or - :meth:`Signature.bind_partial`. This concerns arguments of the kind - *POSITIONAL_OR_KEYWORD* in cases where they can be passed ambiguously - as args or kwargs. In cases of ambiguity the dynamic computation of - args and kwargs always simplifies the given arguments as much as - possible, by dropping keywords and saving them positionally in args. - For example:: - - >>> def test(a=1, b=2, c=3): - ... pass - ... - >>> boundargs = signature(test).bind(a=10, c=13) - >>> boundargs.args - (10,) - >>> boundargs.kwargs - {'c': 13} + :attr:`arguments` attribute. Arguments that can be passed positionally + are included in :attr:`args` instead. .. attribute:: BoundArguments.signature