summaryrefslogtreecommitdiffstats
path: root/Python/ast.c
diff options
context:
space:
mode:
authorRobert Collins <rbtcollins@hp.com>2015-08-11 20:00:06 (GMT)
committerRobert Collins <rbtcollins@hp.com>2015-08-11 20:00:06 (GMT)
commitdf395991f6341be037a5c6df9b14d924d5ac9e95 (patch)
tree5b0bf65fee4d6b2fc5b8f69cacc50a4bddb6d3f0 /Python/ast.c
parent5b9cd7fa2e4b73bf97a1b28c3f3a7b15c9302941 (diff)
downloadcpython-df395991f6341be037a5c6df9b14d924d5ac9e95.zip
cpython-df395991f6341be037a5c6df9b14d924d5ac9e95.tar.gz
cpython-df395991f6341be037a5c6df9b14d924d5ac9e95.tar.bz2
Issue #9232: Support trailing commas in function declarations.
For example, "def f(*, a = 3,): pass" is now legal. Patch from Mark Dickinson.
Diffstat (limited to 'Python/ast.c')
-rw-r--r--Python/ast.c23
1 files changed, 14 insertions, 9 deletions
diff --git a/Python/ast.c b/Python/ast.c
index b572088..c1c3907 100644
--- a/Python/ast.c
+++ b/Python/ast.c
@@ -1260,16 +1260,20 @@ ast_for_arguments(struct compiling *c, const node *n)
and varargslist (lambda definition).
parameters: '(' [typedargslist] ')'
- typedargslist: ((tfpdef ['=' test] ',')*
- ('*' [tfpdef] (',' tfpdef ['=' test])* [',' '**' tfpdef]
- | '**' tfpdef)
- | tfpdef ['=' test] (',' tfpdef ['=' test])* [','])
+ typedargslist: (tfpdef ['=' test] (',' tfpdef ['=' test])* [',' [
+ '*' [tfpdef] (',' tfpdef ['=' test])* [',' ['**' tfpdef [',']]]
+ | '**' tfpdef [',']]]
+ | '*' [tfpdef] (',' tfpdef ['=' test])* [',' ['**' tfpdef [',']]]
+ | '**' tfpdef [','])
tfpdef: NAME [':' test]
- varargslist: ((vfpdef ['=' test] ',')*
- ('*' [vfpdef] (',' vfpdef ['=' test])* [',' '**' vfpdef]
- | '**' vfpdef)
- | vfpdef ['=' test] (',' vfpdef ['=' test])* [','])
+ varargslist: (vfpdef ['=' test] (',' vfpdef ['=' test])* [',' [
+ '*' [vfpdef] (',' vfpdef ['=' test])* [',' ['**' vfpdef [',']]]
+ | '**' vfpdef [',']]]
+ | '*' [vfpdef] (',' vfpdef ['=' test])* [',' ['**' vfpdef [',']]]
+ | '**' vfpdef [',']
+ )
vfpdef: NAME
+
*/
int i, j, k, nposargs = 0, nkwonlyargs = 0;
int nposdefaults = 0, found_default = 0;
@@ -1371,7 +1375,8 @@ ast_for_arguments(struct compiling *c, const node *n)
i += 2; /* the name and the comma */
break;
case STAR:
- if (i+1 >= NCH(n)) {
+ if (i+1 >= NCH(n) ||
+ (i+2 == NCH(n) && TYPE(CHILD(n, i+1)) == COMMA)) {
ast_error(c, CHILD(n, i),
"named arguments must follow bare *");
return NULL;