[Python-checkins] r73033 - in sandbox/trunk/2to3/lib2to3: Grammar.txt tests/data/py2_test_grammar.py tests/data/py3_test_grammar.py

benjamin.peterson python-checkins at python.org
Fri May 29 23:58:32 CEST 2009


Author: benjamin.peterson
Date: Fri May 29 23:58:32 2009
New Revision: 73033
Log:
update grammar for multi with statement
Modified:
 sandbox/trunk/2to3/lib2to3/Grammar.txt
 sandbox/trunk/2to3/lib2to3/tests/data/py2_test_grammar.py
 sandbox/trunk/2to3/lib2to3/tests/data/py3_test_grammar.py
Modified: sandbox/trunk/2to3/lib2to3/Grammar.txt
==============================================================================
--- sandbox/trunk/2to3/lib2to3/Grammar.txt	(original)
+++ sandbox/trunk/2to3/lib2to3/Grammar.txt	Fri May 29 23:58:32 2009
@@ -90,7 +90,8 @@
 	 ['else' ':' suite]
 	 ['finally' ':' suite] |
 	 'finally' ':' suite))
-with_stmt: 'with' test [ with_var ] ':' suite
+with_stmt: 'with' with_item (',' with_item)* ':' suite
+with_item: test ['as' expr]
 with_var: 'as' expr
 # NB compile.c makes sure that the default except clause is last
 except_clause: 'except' [test [(',' | 'as') test]]
Modified: sandbox/trunk/2to3/lib2to3/tests/data/py2_test_grammar.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/tests/data/py2_test_grammar.py	(original)
+++ sandbox/trunk/2to3/lib2to3/tests/data/py2_test_grammar.py	Fri May 29 23:58:32 2009
@@ -1,5 +1,3 @@
-# Python 2's Lib/test/test_grammar.py (r66189)
-
 # Python test set -- part 1, grammar.
 # This just tests whether the parser accepts them all.
 
@@ -922,6 +920,26 @@
 self.assertEqual([x for x, in [(4,), (5,), (6,)]], [4, 5, 6])
 self.assertEqual(list(x for x, in [(7,), (8,), (9,)]), [7, 8, 9])
 
+ def test_with_statement(self):
+ class manager(object):
+ def __enter__(self):
+ return (1, 2)
+ def __exit__(self, *args):
+ pass
+
+ with manager():
+ pass
+ with manager() as x:
+ pass
+ with manager() as (x, y):
+ pass
+ with manager(), manager():
+ pass
+ with manager() as x, manager() as y:
+ pass
+ with manager() as x, manager():
+ pass
+
 def testIfElseExpr(self):
 # Test ifelse expressions in various cases
 def _checkeval(msg, ret):
Modified: sandbox/trunk/2to3/lib2to3/tests/data/py3_test_grammar.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/tests/data/py3_test_grammar.py	(original)
+++ sandbox/trunk/2to3/lib2to3/tests/data/py3_test_grammar.py	Fri May 29 23:58:32 2009
@@ -868,6 +868,26 @@
 self.assertEqual([x for x, in [(4,), (5,), (6,)]], [4, 5, 6])
 self.assertEqual(list(x for x, in [(7,), (8,), (9,)]), [7, 8, 9])
 
+ def test_with_statement(self):
+ class manager(object):
+ def __enter__(self):
+ return (1, 2)
+ def __exit__(self, *args):
+ pass
+
+ with manager():
+ pass
+ with manager() as x:
+ pass
+ with manager() as (x, y):
+ pass
+ with manager(), manager():
+ pass
+ with manager() as x, manager() as y:
+ pass
+ with manager() as x, manager():
+ pass
+
 def testIfElseExpr(self):
 # Test ifelse expressions in various cases
 def _checkeval(msg, ret):


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /