Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
80f0ed5b
Kaydet (Commit)
80f0ed5b
authored
Agu 19, 2008
tarafından
Benjamin Peterson
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
allow keyword args to be passed in after *args #3473
üst
d9ccf8c5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
29 additions
and
12 deletions
+29
-12
expressions.rst
Doc/reference/expressions.rst
+10
-9
Grammar
Grammar/Grammar
+3
-1
test_grammar.py
Lib/test/test_grammar.py
+8
-0
ast.c
Python/ast.c
+5
-0
graminit.c
Python/graminit.c
+3
-2
No files found.
Doc/reference/expressions.rst
Dosyayı görüntüle @
80f0ed5b
...
@@ -625,11 +625,11 @@ of arguments:
...
@@ -625,11 +625,11 @@ of arguments:
call: `primary` "(" [`argument_list` [","]
call: `primary` "(" [`argument_list` [","]
: | `expression` `genexpr_for`] ")"
: | `expression` `genexpr_for`] ")"
argument_list: `positional_arguments` ["," `keyword_arguments`]
argument_list: `positional_arguments` ["," `keyword_arguments`]
:
["," "*" `expression
`]
:
["," "*" `expression`] ["," `keyword_arguments
`]
: ["," "**" `expression`]
:
["," "**" `expression`]
: | `keyword_arguments` ["," "*" `expression`]
: | `keyword_arguments` ["," "*" `expression`]
: ["," "**" `expression`]
:
["," "**" `expression`]
: | "*" `expression` ["," "**" `expression`]
: | "*" `expression` ["," "*
" `expression`] ["," "*
*" `expression`]
: | "**" `expression`
: | "**" `expression`
positional_arguments: `expression` ("," `expression`)*
positional_arguments: `expression` ("," `expression`)*
keyword_arguments: `keyword_item` ("," `keyword_item`)*
keyword_arguments: `keyword_item` ("," `keyword_item`)*
...
@@ -686,12 +686,13 @@ there were no excess keyword arguments.
...
@@ -686,12 +686,13 @@ there were no excess keyword arguments.
If the syntax ``*expression`` appears in the function call, ``expression`` must
If the syntax ``*expression`` appears in the function call, ``expression`` must
evaluate to a sequence. Elements from this sequence are treated as if they were
evaluate to a sequence. Elements from this sequence are treated as if they were
additional positional arguments; if there are positional arguments *x1*,...,*xN*
additional positional arguments; if there are positional arguments *x1*,...,
, and ``expression`` evaluates to a sequence *y1*,...,*yM*, this is equivalent
*xN*, and ``expression`` evaluates to a sequence *y1*, ..., *yM*, this is
to a call with M+N positional arguments *x1*,...,*xN*,*y1*,...,*yM*.
equivalent to a call with M+N positional arguments *x1*, ..., *xN*, *y1*, ...,
*yM*.
A consequence of this is that although the ``*expression`` syntax
appears
A consequence of this is that although the ``*expression`` syntax
may appear
*after*
any
keyword arguments, it is processed *before* the keyword arguments
*after*
some
keyword arguments, it is processed *before* the keyword arguments
(and the ``**expression`` argument, if any -- see below). So::
(and the ``**expression`` argument, if any -- see below). So::
>>> def f(a, b):
>>> def f(a, b):
...
...
Grammar/Grammar
Dosyayı görüntüle @
80f0ed5b
...
@@ -130,7 +130,9 @@ dictmaker: test ':' test (',' test ':' test)* [',']
...
@@ -130,7 +130,9 @@ dictmaker: test ':' test (',' test ':' test)* [',']
classdef: 'class' NAME ['(' [testlist] ')'] ':' suite
classdef: 'class' NAME ['(' [testlist] ')'] ':' suite
arglist: (argument ',')* (argument [',']| '*' test [',' '**' test] | '**' test)
arglist: (argument ',')* (argument [',']
|'*' test (',' argument)* [',' '**' test]
|'**' test)
argument: test [gen_for] | test '=' test # Really [keyword '='] test
argument: test [gen_for] | test '=' test # Really [keyword '='] test
list_iter: list_for | list_if
list_iter: list_for | list_if
...
...
Lib/test/test_grammar.py
Dosyayı görüntüle @
80f0ed5b
...
@@ -282,6 +282,14 @@ class GrammarTests(unittest.TestCase):
...
@@ -282,6 +282,14 @@ class GrammarTests(unittest.TestCase):
def
d32v
((
x
,)):
pass
def
d32v
((
x
,)):
pass
d32v
((
1
,))
d32v
((
1
,))
# keyword arguments after *arglist
def
f
(
*
args
,
**
kwargs
):
return
args
,
kwargs
self
.
assertEquals
(
f
(
1
,
x
=
2
,
*
[
3
,
4
],
y
=
5
),
((
1
,
3
,
4
),
{
'x'
:
2
,
'y'
:
5
}))
self
.
assertRaises
(
SyntaxError
,
eval
,
"f(1, *(2,3), 4)"
)
self
.
assertRaises
(
SyntaxError
,
eval
,
"f(1, x=2, *(3,4), x=5)"
)
# Check ast errors in *args and *kwargs
# Check ast errors in *args and *kwargs
check_syntax_error
(
self
,
"f(*g(1=2))"
)
check_syntax_error
(
self
,
"f(*g(1=2))"
)
check_syntax_error
(
self
,
"f(**g(1=2))"
)
check_syntax_error
(
self
,
"f(**g(1=2))"
)
...
...
Python/ast.c
Dosyayı görüntüle @
80f0ed5b
...
@@ -1898,6 +1898,11 @@ ast_for_call(struct compiling *c, const node *n, expr_ty func)
...
@@ -1898,6 +1898,11 @@ ast_for_call(struct compiling *c, const node *n, expr_ty func)
"non-keyword arg after keyword arg"
);
"non-keyword arg after keyword arg"
);
return
NULL
;
return
NULL
;
}
}
if
(
vararg
)
{
ast_error
(
CHILD
(
ch
,
0
),
"only named arguments may follow *expression"
);
return
NULL
;
}
e
=
ast_for_expr
(
c
,
CHILD
(
ch
,
0
));
e
=
ast_for_expr
(
c
,
CHILD
(
ch
,
0
));
if
(
!
e
)
if
(
!
e
)
return
NULL
;
return
NULL
;
...
...
Python/graminit.c
Dosyayı görüntüle @
80f0ed5b
...
@@ -1609,7 +1609,8 @@ static arc arcs_74_5[2] = {
...
@@ -1609,7 +1609,8 @@ static arc arcs_74_5[2] = {
static
arc
arcs_74_6
[
1
]
=
{
static
arc
arcs_74_6
[
1
]
=
{
{
0
,
6
},
{
0
,
6
},
};
};
static
arc
arcs_74_7
[
1
]
=
{
static
arc
arcs_74_7
[
2
]
=
{
{
162
,
5
},
{
31
,
3
},
{
31
,
3
},
};
};
static
state
states_74
[
8
]
=
{
static
state
states_74
[
8
]
=
{
...
@@ -1620,7 +1621,7 @@ static state states_74[8] = {
...
@@ -1620,7 +1621,7 @@ static state states_74[8] = {
{
4
,
arcs_74_4
},
{
4
,
arcs_74_4
},
{
2
,
arcs_74_5
},
{
2
,
arcs_74_5
},
{
1
,
arcs_74_6
},
{
1
,
arcs_74_6
},
{
1
,
arcs_74_7
},
{
2
,
arcs_74_7
},
};
};
static
arc
arcs_75_0
[
1
]
=
{
static
arc
arcs_75_0
[
1
]
=
{
{
28
,
1
},
{
28
,
1
},
...
...
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