[pypy-commit] pypy py3k: Update grammar and compiler to recognize (and skip for now)
amauryfa
noreply at buildbot.pypy.org
Wed Oct 12 22:23:35 CEST 2011
Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: py3k
Changeset: r47994:16f4dc189f4e
Date: 2011-10-12 22:19 +0200
http://bitbucket.org/pypy/pypy/changeset/16f4dc189f4e/
Log: Update grammar and compiler to recognize (and skip for now) the
single * used to separate keywords-only arguments
diff --git a/pypy/interpreter/astcompiler/astbuilder.py b/pypy/interpreter/astcompiler/astbuilder.py
--- a/pypy/interpreter/astcompiler/astbuilder.py
+++ b/pypy/interpreter/astcompiler/astbuilder.py
@@ -517,7 +517,7 @@
while i < child_count:
argument = arguments_node.children[i]
arg_type = argument.type
- if arg_type == syms.fpdef:
+ if arg_type == syms.tfpdef:
parenthesized = False
complex_args = False
while True:
@@ -554,12 +554,16 @@
break
elif arg_type == tokens.STAR:
name_node = arguments_node.children[i + 1]
- variable_arg = name_node.value
- self.check_forbidden_name(variable_arg, name_node)
- i += 3
+ if name_node.type == tokens.COMMA:
+ # XXX for now
+ i += 2
+ else:
+ variable_arg = name_node.children[0].value
+ self.check_forbidden_name(variable_arg, name_node)
+ i += 3
elif arg_type == tokens.DOUBLESTAR:
name_node = arguments_node.children[i + 1]
- keywords_arg = name_node.value
+ keywords_arg = name_node.children[0].value
self.check_forbidden_name(keywords_arg, name_node)
i += 3
else:
diff --git a/pypy/interpreter/astcompiler/test/test_compiler.py b/pypy/interpreter/astcompiler/test/test_compiler.py
--- a/pypy/interpreter/astcompiler/test/test_compiler.py
+++ b/pypy/interpreter/astcompiler/test/test_compiler.py
@@ -89,12 +89,12 @@
yield self.st, func, "f(0)", 0
def test_argtuple(self):
- yield (self.simple_test, "def f( x, (y,z) ): return x,y,z",
- "f((1,2),(3,4))", ((1,2),3,4))
- yield (self.simple_test, "def f( x, (y,(z,t)) ): return x,y,z,t",
- "f(1,(2,(3,4)))", (1,2,3,4))
- yield (self.simple_test, "def f(((((x,),y),z),t),u): return x,y,z,t,u",
- "f(((((1,),2),3),4),5)", (1,2,3,4,5))
+ yield (self.error_test, "def f( x, (y,z) ): return x,y,z",
+ SyntaxError)
+ yield (self.error_test, "def f( x, (y,(z,t)) ): return x,y,z,t",
+ SyntaxError)
+ yield (self.error_test, "def f(((((x,),y),z),t),u): return x,y,z,t,u",
+ SyntaxError)
def test_constants(self):
for c in expressions.constants:
@@ -236,6 +236,14 @@
yield self.st, decl + "x=f(5, b=2, **{'a': 8})", "x", [5, ('a', 8),
('b', 2)]
+ def test_kwonly(self):
+ decl = py.code.Source("""
+ def f(a, *, b):
+ return a, b
+ """)
+ decl = str(decl) + '\n'
+ yield self.st, decl + "x=f(1, b=2)", "x", (1, 2)
+
def test_listmakers(self):
yield (self.st,
"l = [(j, i) for j in range(10) for i in range(j)"
diff --git a/pypy/interpreter/pyparser/data/Grammar3.2 b/pypy/interpreter/pyparser/data/Grammar3.2
--- a/pypy/interpreter/pyparser/data/Grammar3.2
+++ b/pypy/interpreter/pyparser/data/Grammar3.2
@@ -23,12 +23,15 @@
decorators: decorator+
decorated: decorators (classdef | funcdef)
funcdef: 'def' NAME parameters ':' suite
-parameters: '(' [varargslist] ')'
-varargslist: ((fpdef ['=' test] ',')*
- ('*' NAME [',' '**' NAME] | '**' NAME) |
- fpdef ['=' test] (',' fpdef ['=' test])* [','])
-fpdef: NAME | '(' fplist ')'
-fplist: fpdef (',' fpdef)* [',']
+parameters: '(' [typedargslist] ')'
+typedargslist: (tfpdef ['=' test] (',' tfpdef ['=' test])* [','
+ ['*' [tfpdef] (',' tfpdef ['=' test])* [',' '**' tfpdef] | '**' tfpdef]]
+ | '*' [tfpdef] (',' tfpdef ['=' test])* [',' '**' tfpdef] | '**' tfpdef)
+tfpdef: NAME [':' test]
+varargslist: (vfpdef ['=' test] (',' vfpdef ['=' test])* [','
+ ['*' [vfpdef] (',' vfpdef ['=' test])* [',' '**' vfpdef] | '**' vfpdef]]
+ | '*' [vfpdef] (',' vfpdef ['=' test])* [',' '**' vfpdef] | '**' vfpdef)
+vfpdef: NAME
stmt: simple_stmt | compound_stmt
simple_stmt: small_stmt (';' small_stmt)* [';'] NEWLINE
More information about the pypy-commit
mailing list