[Python-checkins] r56424 - in sandbox/trunk/2to3: fixes/fix_except.py tests/test_fixers.py

collin.winter python-checkins at python.org
Tue Jul 17 23:11:08 CEST 2007


Author: collin.winter
Date: Tue Jul 17 23:11:08 2007
New Revision: 56424

Modified:
   sandbox/trunk/2to3/   (props changed)
   sandbox/trunk/2to3/fixes/fix_except.py
   sandbox/trunk/2to3/tests/test_fixers.py
Log:
Fix a bug in fix_except related to prefix handling.


Modified: sandbox/trunk/2to3/fixes/fix_except.py
==============================================================================
--- sandbox/trunk/2to3/fixes/fix_except.py	(original)
+++ sandbox/trunk/2to3/fixes/fix_except.py	Tue Jul 17 23:11:08 2007
@@ -43,7 +43,6 @@
     """
 
     def transform(self, node, results):
-        assert results
         syms = self.syms
 
         try_cleanup = [ch.clone() for ch in results['cleanup']]
@@ -80,6 +79,10 @@
                     for child in reversed(suite_stmts[:i]):
                         e_suite.insert_child(0, child)
                     e_suite.insert_child(i, assign)
+                elif N.get_prefix() == "":
+                    # No space after a comma is legal; no space after "as",
+                    # not so much.
+                    N.set_prefix(" ")
 
         #TODO(cwinter) fix this when children becomes a smart list
         children = [c.clone() for c in node.children[:3]] + try_cleanup

Modified: sandbox/trunk/2to3/tests/test_fixers.py
==============================================================================
--- sandbox/trunk/2to3/tests/test_fixers.py	(original)
+++ sandbox/trunk/2to3/tests/test_fixers.py	Tue Jul 17 23:11:08 2007
@@ -502,6 +502,32 @@
                 pass"""
         self.check(b, a)
 
+    def test_simple(self):
+        b = """
+            try:
+                pass
+            except Foo, e:
+                pass"""
+        a = """
+            try:
+                pass
+            except Foo as e:
+                pass"""
+        self.check(b, a)
+
+    def test_simple_no_space_before_target(self):
+        b = """
+            try:
+                pass
+            except Foo,e:
+                pass"""
+        a = """
+            try:
+                pass
+            except Foo as e:
+                pass"""
+        self.check(b, a)
+
     def test_tuple_unpack(self):
         b = """
             def foo():


More information about the Python-checkins mailing list