Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dca249b

Browse files
committed
Merge 3.5 (issue #24791)
2 parents d66f43d + 14acf5f commit dca249b

5 files changed

Lines changed: 42 additions & 38 deletions

File tree

Grammar/Grammar

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ arglist: argument (',' argument)* [',']
137137
argument: ( test [comp_for] |
138138
test '=' test |
139139
'**' test |
140-
star_expr )
140+
'*' test )
141141

142142
comp_iter: comp_for | comp_if
143143
comp_for: 'for' exprlist 'in' or_test [comp_iter]

Lib/test/test_grammar.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@ def d01(a=1): pass
205205
d01()
206206
d01(1)
207207
d01(*(1,))
208+
d01(*[] or [2])
209+
d01(*() or (), *{} and (), **() or {})
208210
d01(**{'a':2})
209211
d01(**{'a':2} or {})
210212
def d11(a, b=1): pass

Modules/parsermodule.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2859,8 +2859,8 @@ validate_arglist(node *tree)
28592859

28602860
/* argument: ( test [comp_for] |
28612861
* test '=' test |
2862-
* '**' expr |
2863-
* star_expr )
2862+
* '**' test |
2863+
* '*' test )
28642864
*/
28652865
static int
28662866
validate_argument(node *tree)
@@ -2873,8 +2873,11 @@ validate_argument(node *tree)
28732873
if (TYPE(CHILD(tree, 0)) == DOUBLESTAR) {
28742874
res = validate_test(CHILD(tree, 1));
28752875
}
2876+
else if (TYPE(CHILD(tree, 0)) == STAR) {
2877+
res = validate_test(CHILD(tree, 1));
2878+
}
28762879
else if (nch == 1) {
2877-
res = validate_test_or_star_expr(CHILD(tree, 0));
2880+
res = validate_test(CHILD(tree, 0));
28782881
}
28792882
else if (nch == 2) {
28802883
res = (validate_test(CHILD(tree, 0))

Python/ast.c

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2664,45 +2664,44 @@ ast_for_call(struct compiling *c, const node *n, expr_ty func)
26642664
expr_ty e;
26652665
node *chch = CHILD(ch, 0);
26662666
if (NCH(ch) == 1) {
2667-
if (TYPE(chch) == star_expr) {
2668-
/* an iterable argument unpacking */
2669-
expr_ty starred;
2667+
/* a positional argument */
2668+
if (nkeywords) {
26702669
if (ndoublestars) {
26712670
ast_error(c, chch,
2672-
"iterable argument unpacking follows "
2671+
"positional argument follows "
26732672
"keyword argument unpacking");
2674-
return NULL;
26752673
}
2676-
e = ast_for_expr(c, CHILD(chch, 1));
2677-
if (!e)
2678-
return NULL;
2679-
starred = Starred(e, Load, LINENO(chch),
2680-
chch->n_col_offset,
2681-
c->c_arena);
2682-
if (!starred)
2683-
return NULL;
2684-
asdl_seq_SET(args, nargs++, starred);
2685-
}
2686-
else {
2687-
/* a positional argument */
2688-
if (nkeywords) {
2689-
if (ndoublestars) {
2690-
ast_error(c, chch,
2691-
"positional argument follows "
2692-
"keyword argument unpacking");
2693-
}
2694-
else {
2695-
ast_error(c, chch,
2696-
"positional argument follows "
2697-
"keyword argument");
2698-
}
2699-
return NULL;
2674+
else {
2675+
ast_error(c, chch,
2676+
"positional argument follows "
2677+
"keyword argument");
27002678
}
2701-
e = ast_for_expr(c, chch);
2702-
if (!e)
2703-
return NULL;
2704-
asdl_seq_SET(args, nargs++, e);
2679+
return NULL;
27052680
}
2681+
e = ast_for_expr(c, chch);
2682+
if (!e)
2683+
return NULL;
2684+
asdl_seq_SET(args, nargs++, e);
2685+
}
2686+
else if (TYPE(chch) == STAR) {
2687+
/* an iterable argument unpacking */
2688+
expr_ty starred;
2689+
if (ndoublestars) {
2690+
ast_error(c, chch,
2691+
"iterable argument unpacking follows "
2692+
"keyword argument unpacking");
2693+
return NULL;
2694+
}
2695+
e = ast_for_expr(c, CHILD(ch, 1));
2696+
if (!e)
2697+
return NULL;
2698+
starred = Starred(e, Load, LINENO(chch),
2699+
chch->n_col_offset,
2700+
c->c_arena);
2701+
if (!starred)
2702+
return NULL;
2703+
asdl_seq_SET(args, nargs++, starred);
2704+
27062705
}
27072706
else if (TYPE(chch) == DOUBLESTAR) {
27082707
/* a keyword argument unpacking */

Python/graminit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1744,7 +1744,7 @@ static state states_77[3] = {
17441744
static arc arcs_78_0[3] = {
17451745
{26, 1},
17461746
{34, 2},
1747-
{50, 3},
1747+
{33, 2},
17481748
};
17491749
static arc arcs_78_1[3] = {
17501750
{164, 3},

0 commit comments

Comments
 (0)