Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
850d3980
Commit
850d3980
authored
Dec 12, 2001
by
Michael W. Hudson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix for
[ #429329 ] actual-parameters *arg, **kws not doc'd
parent
be5ce18e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
2 deletions
+45
-2
Doc/ref/ref5.tex
Doc/ref/ref5.tex
+45
-2
No files found.
Doc/ref/ref5.tex
View file @
850d3980
...
...
@@ -439,8 +439,13 @@ series of arguments:
\production
{
call
}
{
\token
{
primary
}
"(" [
\token
{
argument
_
list
}
[","]] ")"
}
\production
{
argument
_
list
}
{
\token
{
positional
_
arguments
}
[","
\token
{
keyword
_
arguments
}
]
|
\token
{
keyword
_
arguments
}}
{
\token
{
positional
_
arguments
}
[","
\token
{
keyword
_
arguments
}
["," "*"
\token
{
expression
}
["," "**"
\token
{
expression
}
]]]
|
\token
{
keyword
_
arguments
}
["," "*"
\token
{
expression
}
["," "**"
\token
{
expression
}
]]
| "*"
\token
{
expression
}
["," "**"
\token
{
expression
}
]
| "**"
\token
{
expression
}
}
\production
{
positional
_
arguments
}
{
\token
{
expression
}
(","
\token
{
expression
}
)*
}
\production
{
keyword
_
arguments
}
...
...
@@ -495,6 +500,44 @@ excess keyword arguments (using the keywords as keys and the argument
values as corresponding values), or a (new) empty dictionary if there
were no excess keyword arguments.
If the syntax
\samp
{
*expression
}
appears in the function call,
\samp
{
expression
}
must evaluate to a sequence. Elements from this
sequence are treated as if they were additional positional arguments;
if there are postional arguments
\var
{
x1
}
,...,
\var
{
xN
}
, and
\samp
{
expression
}
evaluates to a sequence
\var
{
y1
}
,...,
\var
{
yM
}
, this
is equivalent to a call with M+N positional arguments
\var
{
x1
}
,...,
\var
{
xN
}
,
\var
{
y1
}
,...,
\var
{
yM
}
.
A consequence of this is that although the
\samp
{
*expression
}
syntax
appears
\emph
{
after
}
any keyword arguments, it is processed
\emph
{
before
}
the keyword arguments (and the
\samp
{
**expression
}
argument, if any -- see below). So:
\begin{verbatim}
>>> def f(a, b):
... print a, b
...
>>> f(b=1, *(2,))
2 1
>>> f(a=1, *(2,))
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: f() got multiple values for keyword argument 'a'
>>> f(1, *(2,))
1 2
\end{verbatim}
It is unusual for both keyword arguments and the
\samp
{
*expression
}
syntax to be used in the same call, so in practice this confusion does
not arise.
If the syntax
\samp
{
**expression
}
appears in the function call,
\samp
{
expression
}
must evaluate to a (subclass of) dictionary, the
contents of which are treated as additional keyword arguments. In the
case of a keyword appearing in both
\samp
{
expression
}
and as an
explicit keyword argument, a
\exception
{
TypeError
}
exception is
raised.
Formal parameters using the syntax
\samp
{
*identifier
}
or
\samp
{
**identifier
}
cannot be used as positional argument slots or
as keyword argument names. Formal parameters using the syntax
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment