[Python-checkins] r57338 - in sandbox/trunk/2to3: README fixes/fix_standarderror.py tests/test_fixers.py

collin.winter python-checkins at python.org
Thu Aug 23 20:35:20 CEST 2007


Author: collin.winter
Date: Thu Aug 23 20:35:19 2007
New Revision: 57338

Added:
   sandbox/trunk/2to3/fixes/fix_standarderror.py
Modified:
   sandbox/trunk/2to3/   (props changed)
   sandbox/trunk/2to3/README
   sandbox/trunk/2to3/tests/test_fixers.py
Log:
 r665 at Silves:  collinwinter | 2007-08-23 11:35:15 -0700
 Add a fixer for StandardError -> Exception.


Modified: sandbox/trunk/2to3/README
==============================================================================
--- sandbox/trunk/2to3/README	(original)
+++ sandbox/trunk/2to3/README	Thu Aug 23 20:35:19 2007
@@ -77,6 +77,8 @@
 
 * **fix_repr** - swap backticks for repr() calls.
 
+* **fix_standarderror** - StandardError -> Exception.
+
 * **fix_throw** - fix generator.throw() calls to be 3.0-compliant (PEP 3109).
 
 * **fix_tuple_params** - remove tuple parameters from function, method and

Added: sandbox/trunk/2to3/fixes/fix_standarderror.py
==============================================================================
--- (empty file)
+++ sandbox/trunk/2to3/fixes/fix_standarderror.py	Thu Aug 23 20:35:19 2007
@@ -0,0 +1,18 @@
+# Copyright 2007 Google, Inc. All Rights Reserved.
+# Licensed to PSF under a Contributor Agreement.
+
+"""Fixer for StandardError -> Exception."""
+
+# Local imports
+from fixes import basefix
+from fixes.util import Name
+
+
+class FixStandarderror(basefix.BaseFix):
+
+    PATTERN = """
+              'StandardError'
+              """
+
+    def transform(self, node, results):
+        return Name("Exception", prefix=node.get_prefix())

Modified: sandbox/trunk/2to3/tests/test_fixers.py
==============================================================================
--- sandbox/trunk/2to3/tests/test_fixers.py	(original)
+++ sandbox/trunk/2to3/tests/test_fixers.py	Thu Aug 23 20:35:19 2007
@@ -2308,6 +2308,22 @@
             """
         self.warns_unchanged(a, "You should use a for loop here")
 
+class Test_standarderror(FixerTestCase):
+    fixer = "standarderror"
+
+    def test(self):
+        b = """x =    StandardError()"""
+        a = """x =    Exception()"""
+        self.check(b, a)
+
+        b = """x = StandardError(a, b, c)"""
+        a = """x = Exception(a, b, c)"""
+        self.check(b, a)
+
+        b = """f(2 + StandardError(a, b, c))"""
+        a = """f(2 + Exception(a, b, c))"""
+        self.check(b, a)
+
 class Test_types(FixerTestCase):
     fixer = "types"
 


More information about the Python-checkins mailing list