[Python-checkins] r57885 - in sandbox/trunk/2to3: fixes/basefix.py fixes/fix_idioms.py refactor.py

collin.winter python-checkins at python.org
Sat Sep 1 22:20:31 CEST 2007


Author: collin.winter
Date: Sat Sep  1 22:20:30 2007
New Revision: 57885

Modified:
   sandbox/trunk/2to3/   (props changed)
   sandbox/trunk/2to3/fixes/basefix.py
   sandbox/trunk/2to3/fixes/fix_idioms.py
   sandbox/trunk/2to3/refactor.py
Log:
Add a notion of explicit v implicit fixers. This is to deal with the fact that fix_idioms can cause undesirable semantics changes in certain situations and so shouldn't automatically be run.


Modified: sandbox/trunk/2to3/fixes/basefix.py
==============================================================================
--- sandbox/trunk/2to3/fixes/basefix.py	(original)
+++ sandbox/trunk/2to3/fixes/basefix.py	Sat Sep  1 22:20:30 2007
@@ -35,6 +35,7 @@
     numbers = itertools.count(1) # For new_name()
     used_names = set() # A set of all used NAMEs
     order = "post" # Does the fixer prefer pre- or post-order traversal
+    explicit = False # Is this ignored by refactor.py -f all?
 
     # Shortcut for access to Python grammar symbols
     syms = pygram.python_symbols

Modified: sandbox/trunk/2to3/fixes/fix_idioms.py
==============================================================================
--- sandbox/trunk/2to3/fixes/fix_idioms.py	(original)
+++ sandbox/trunk/2to3/fixes/fix_idioms.py	Sat Sep  1 22:20:30 2007
@@ -19,6 +19,8 @@
 
 class FixIdioms(basefix.BaseFix):
 
+    explicit = True # The user must ask for this fixer
+
     PATTERN = """
         isinstance=comparison< %s %s T=any > |
         isinstance=comparison< T=any %s %s > |

Modified: sandbox/trunk/2to3/refactor.py
==============================================================================
--- sandbox/trunk/2to3/refactor.py	(original)
+++ sandbox/trunk/2to3/refactor.py	Sat Sep  1 22:20:30 2007
@@ -125,7 +125,8 @@
         pre_order_fixers = []
         post_order_fixers = []
         fix_names = self.options.fix
-        if not fix_names or "all" in fix_names:
+        get_all_fixers = not fix_names or "all" in fix_names
+        if get_all_fixers:
             fix_names = get_all_fix_names()
         for fix_name in fix_names:
             try:
@@ -147,9 +148,12 @@
                 self.log_error("Can't instantiate fixes.fix_%s.%s()",
                                fix_name, class_name, exc_info=True)
                 continue
+            if fixer.explicit and get_all_fixers:
+                self.log_message("Skipping implicit fixer: %s", fix_name)
+                continue
+
             if self.options.verbose:
                 self.log_message("Adding transformation: %s", fix_name)
-
             if fixer.order == "pre":
                 pre_order_fixers.append(fixer)
             elif fixer.order == "post":


More information about the Python-checkins mailing list