[Python-checkins] r64293 - python/branches/tlee-ast-optimize/Lib/test/test_grammar.py

thomas.lee python-checkins at python.org
Sun Jun 15 15:18:49 CEST 2008


Author: thomas.lee
Date: Sun Jun 15 15:18:49 2008
New Revision: 64293

Log:
Added code to testFor to check potential optimizations of empty for loops still call the 'else' body.

Modified:
   python/branches/tlee-ast-optimize/Lib/test/test_grammar.py

Modified: python/branches/tlee-ast-optimize/Lib/test/test_grammar.py
==============================================================================
--- python/branches/tlee-ast-optimize/Lib/test/test_grammar.py	(original)
+++ python/branches/tlee-ast-optimize/Lib/test/test_grammar.py	Sun Jun 15 15:18:49 2008
@@ -612,6 +612,16 @@
             result.append(x)
         self.assertEqual(result, [1, 2, 3])
 
+        #
+        # Ensure that the else: clause is executed for an empty sequence
+        #
+        n = 0
+        for x in []:
+            n = 1
+        else:
+            n = 2
+        self.assertEqual(2, n)
+
     def testTry(self):
         ### try_stmt: 'try' ':' suite (except_clause ':' suite)+ ['else' ':' suite]
         ###         | 'try' ':' suite 'finally' ':' suite


More information about the Python-checkins mailing list