[Python-checkins] r61601 - in sandbox/trunk/2to3/lib2to3: fixes/basefix.py fixes/fix_except.py fixes/fix_future.py fixes/fix_has_key.py fixes/fix_idioms.py fixes/fix_imports.py fixes/fix_map.py fixes/fix_ne.py fixes/fix_next.py fixes/fix_print.py fixes/fix_raise.py fixes/fix_renames.py fixes/fix_repr.py fixes/fix_tuple_params.py fixes/fix_unicode.py fixes/fix_ws_comma.py fixes/fix_zip.py fixes/util.py refactor.py tests/benchmark.py tests/test_parser.py tests/test_pytree.py

martin.v.loewis python-checkins at python.org
Wed Mar 19 06:21:13 CET 2008


Author: martin.v.loewis
Date: Wed Mar 19 06:21:12 2008
New Revision: 61601

Modified:
   sandbox/trunk/2to3/lib2to3/fixes/basefix.py
   sandbox/trunk/2to3/lib2to3/fixes/fix_except.py
   sandbox/trunk/2to3/lib2to3/fixes/fix_future.py
   sandbox/trunk/2to3/lib2to3/fixes/fix_has_key.py
   sandbox/trunk/2to3/lib2to3/fixes/fix_idioms.py
   sandbox/trunk/2to3/lib2to3/fixes/fix_imports.py
   sandbox/trunk/2to3/lib2to3/fixes/fix_map.py
   sandbox/trunk/2to3/lib2to3/fixes/fix_ne.py
   sandbox/trunk/2to3/lib2to3/fixes/fix_next.py
   sandbox/trunk/2to3/lib2to3/fixes/fix_print.py
   sandbox/trunk/2to3/lib2to3/fixes/fix_raise.py
   sandbox/trunk/2to3/lib2to3/fixes/fix_renames.py
   sandbox/trunk/2to3/lib2to3/fixes/fix_repr.py
   sandbox/trunk/2to3/lib2to3/fixes/fix_tuple_params.py
   sandbox/trunk/2to3/lib2to3/fixes/fix_unicode.py
   sandbox/trunk/2to3/lib2to3/fixes/fix_ws_comma.py
   sandbox/trunk/2to3/lib2to3/fixes/fix_zip.py
   sandbox/trunk/2to3/lib2to3/fixes/util.py
   sandbox/trunk/2to3/lib2to3/refactor.py
   sandbox/trunk/2to3/lib2to3/tests/benchmark.py
   sandbox/trunk/2to3/lib2to3/tests/test_parser.py
   sandbox/trunk/2to3/lib2to3/tests/test_pytree.py
Log:
Fix whitespace.


Modified: sandbox/trunk/2to3/lib2to3/fixes/basefix.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/basefix.py	(original)
+++ sandbox/trunk/2to3/lib2to3/fixes/basefix.py	Wed Mar 19 06:21:12 2008
@@ -87,7 +87,7 @@
         Args:
           node: the root of the parse tree that matched the fixer.
           results: a dict mapping symbolic names to part of the match.
-          
+
         Returns:
           None, or a node that is a modified copy of the
           argument node.  The node argument may also be modified in-place to
@@ -146,7 +146,7 @@
     def start_tree(self, tree, filename):
         """Some fixers need to maintain tree-wide state.
         This method is called once, at the start of tree fix-up.
-        
+
         tree - the root node of the tree to be processed.
         filename - the name of the file the tree came from.
         """
@@ -158,7 +158,7 @@
     def finish_tree(self, tree, filename):
         """Some fixers need to maintain tree-wide state.
         This method is called once, at the conclusion of tree fix-up.
-        
+
         tree - the root node of the tree to be processed.
         filename - the name of the file the tree came from.
         """

Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_except.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_except.py	(original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_except.py	Wed Mar 19 06:21:12 2008
@@ -3,19 +3,19 @@
 The following cases will be converted:
 
 - "except E, T:" where T is a name:
-    
+
     except E as T:
-    
+
 - "except E, T:" where T is not a name, tuple or list:
-    
+
         except E as t:
             T = t
-        
+
     This is done because the target of an "except" clause must be a
     name.
-    
+
 - "except E, T:" where T is a tuple or list literal:
-    
+
         except E as t:
             T = t.args
 """
@@ -39,7 +39,7 @@
     try_stmt< 'try' ':' suite
                   cleanup=((except_clause ':' suite)+ ['else' ':' suite]
                                                       ['finally' ':' suite]
-	                       | 'finally' ':' suite) >
+                               | 'finally' ':' suite) >
     """
 
     def transform(self, node, results):

Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_future.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_future.py	(original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_future.py	Wed Mar 19 06:21:12 2008
@@ -2,15 +2,14 @@
 
 from __future__ import foo is replaced with an empty line.
 """
-# Author: Christian Heimes 
+# Author: Christian Heimes
 
 # Local imports
 from . import basefix
-from .util import BlankLine 
+from .util import BlankLine
 
 class FixFuture(basefix.BaseFix):
     PATTERN = """import_from< 'from' module_name="__future__" 'import' any >"""
 
     def transform(self, node, results):
         return BlankLine()
-

Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_has_key.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_has_key.py	(original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_has_key.py	Wed Mar 19 06:21:12 2008
@@ -18,14 +18,14 @@
     m = d.has_key
     if m(k):
         ...
-        
+
    Only *calls* to has_key() are converted. While it is possible to
    convert the above to something like
-   
+
     m = d.__contains__
     if m(k):
         ...
-        
+
    this is currently not done.
 """
 

Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_idioms.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_idioms.py	(original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_idioms.py	Wed Mar 19 06:21:12 2008
@@ -5,7 +5,7 @@
     type(x) is T -> isinstance(x, T)
     type(x) != T -> not isinstance(x, T)
     type(x) is not T -> not isinstance(x, T)
-    
+
 * Change "while 1:" into "while True:".
 
 * Change both
@@ -19,7 +19,7 @@
     v = EXPR
     v.sort()
     foo(v)
-    
+
 into
 
     v = sorted(EXPR)

Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_imports.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_imports.py	(original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_imports.py	Wed Mar 19 06:21:12 2008
@@ -16,7 +16,7 @@
 
 MAPPING = {"StringIO":  ("io", ["StringIO"]),
            "cStringIO": ("io", ["StringIO"]),
-           "__builtin__" : ("builtins", builtin_names), 
+           "__builtin__" : ("builtins", builtin_names),
           }
 
 
@@ -86,4 +86,4 @@
             bare_name = bare_name[0]
             new_name = self.replace.get(bare_name.value)
             if new_name:
-              bare_name.replace(Name(new_name, prefix=bare_name.get_prefix()))
+                bare_name.replace(Name(new_name, prefix=bare_name.get_prefix()))

Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_map.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_map.py	(original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_map.py	Wed Mar 19 06:21:12 2008
@@ -69,7 +69,7 @@
             # If a future map has been imported for this file, we won't
             # be making any modifications
             return
-            
+
         if node.parent.type == syms.simple_stmt:
             self.warning(node, "You should use a for loop here")
             new = node.clone()

Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_ne.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_ne.py	(original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_ne.py	Wed Mar 19 06:21:12 2008
@@ -17,6 +17,6 @@
         return node.type == token.NOTEQUAL and node.value == "<>"
 
     def transform(self, node, results):
-      new = pytree.Leaf(token.NOTEQUAL, "!=")
-      new.set_prefix(node.get_prefix())
-      return new
+        new = pytree.Leaf(token.NOTEQUAL, "!=")
+        new.set_prefix(node.get_prefix())
+        return new

Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_next.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_next.py	(original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_next.py	Wed Mar 19 06:21:12 2008
@@ -47,12 +47,12 @@
         mod = results.get("mod")
 
         if base:
-          if self.shadowed_next:
-              attr.replace(Name("__next__", prefix=attr.get_prefix()))
-          else:
-              base = [n.clone() for n in base]
-              base[0].set_prefix("")
-              node.replace(Call(Name("next", prefix=node.get_prefix()), base))
+            if self.shadowed_next:
+                attr.replace(Name("__next__", prefix=attr.get_prefix()))
+            else:
+                base = [n.clone() for n in base]
+                base[0].set_prefix("")
+                node.replace(Call(Name("next", prefix=node.get_prefix()), base))
         elif name:
             n = Name("__next__", prefix=name.get_prefix())
             name.replace(n)

Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_print.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_print.py	(original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_print.py	Wed Mar 19 06:21:12 2008
@@ -5,7 +5,7 @@
 
 Change:
     'print'          into 'print()'
-    'print ...'	     into 'print(...)'
+    'print ...'      into 'print(...)'
     'print ... ,'    into 'print(..., end=" ")'
     'print >>x, ...' into 'print(..., file=x)'
 """

Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_raise.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_raise.py	(original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_raise.py	Wed Mar 19 06:21:12 2008
@@ -12,9 +12,9 @@
 CAVEATS:
 1) "raise E, V" will be incorrectly translated if V is an exception
    instance. The correct Python 3 idiom is
-   
+
         raise E from V
-        
+
    but since we can't detect instance-hood by syntax alone and since
    any client code would have to be changed as well, we don't automate
    this.
@@ -48,11 +48,11 @@
         # Since Python 3 will not support this, we recurse down any tuple
         # literals, always taking the first element.
         if is_tuple(exc):
-          while is_tuple(exc):
-              # exc.children[1:-1] is the unparenthesized tuple
-              # exc.children[1].children[0] is the first element of the tuple
-              exc = exc.children[1].children[0].clone()
-          exc.set_prefix(" ")
+            while is_tuple(exc):
+                # exc.children[1:-1] is the unparenthesized tuple
+                # exc.children[1].children[0] is the first element of the tuple
+                exc = exc.children[1].children[0].clone()
+            exc.set_prefix(" ")
 
         if "val" not in results:
             # One-argument raise

Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_renames.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_renames.py	(original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_renames.py	Wed Mar 19 06:21:12 2008
@@ -63,8 +63,7 @@
         attr_name = results.get("attr_name")
         #bare_name = results.get("bare_name")
         #import_mod = results.get("module")
-      
+
         if mod_name and attr_name:
             new_attr = LOOKUP[(mod_name.value, attr_name.value)]
             attr_name.replace(Name(new_attr, prefix=attr_name.get_prefix()))
-

Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_repr.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_repr.py	(original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_repr.py	Wed Mar 19 06:21:12 2008
@@ -15,8 +15,8 @@
               """
 
     def transform(self, node, results):
-      expr = results["expr"].clone()
+        expr = results["expr"].clone()
 
-      if expr.type == self.syms.testlist1:
-          expr = self.parenthesize(expr)
-      return Call(Name("repr"), [expr], prefix=node.get_prefix())
+        if expr.type == self.syms.testlist1:
+            expr = self.parenthesize(expr)
+        return Call(Name("repr"), [expr], prefix=node.get_prefix())

Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_tuple_params.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_tuple_params.py	(original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_tuple_params.py	Wed Mar 19 06:21:12 2008
@@ -2,7 +2,7 @@
 
 def func(((a, b), c), d):
     ...
-    
+
     ->
 
 def func(x, d):
@@ -10,7 +10,7 @@
     ...
 
 It will also support lambdas:
-  
+
     lambda (x, y): x + y -> lambda t: t[0] + t[1]
 
     # The parens are a syntax error in Python 3

Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_unicode.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_unicode.py	(original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_unicode.py	Wed Mar 19 06:21:12 2008
@@ -8,21 +8,21 @@
 
 class FixUnicode(basefix.BaseFix):
 
-  PATTERN = "STRING | NAME<'unicode' | 'unichr'>"
+    PATTERN = "STRING | NAME<'unicode' | 'unichr'>"
 
-  def transform(self, node, results):
-    if node.type == token.NAME:
-      if node.value == "unicode":
-        new = node.clone()
-        new.value = "str"
-        return new
-      if node.value == "unichr":
-        new = node.clone()
-        new.value = "chr"
-        return new
-      # XXX Warn when __unicode__ found?
-    elif node.type == token.STRING:
-      if re.match(r"[uU][rR]?[\'\"]", node.value):
-        new = node.clone()
-        new.value = new.value[1:]
-        return new
+    def transform(self, node, results):
+        if node.type == token.NAME:
+            if node.value == "unicode":
+                new = node.clone()
+                new.value = "str"
+                return new
+            if node.value == "unichr":
+                new = node.clone()
+                new.value = "chr"
+                return new
+            # XXX Warn when __unicode__ found?
+        elif node.type == token.STRING:
+            if re.match(r"[uU][rR]?[\'\"]", node.value):
+                new = node.clone()
+                new.value = new.value[1:]
+                return new

Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_ws_comma.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_ws_comma.py	(original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_ws_comma.py	Wed Mar 19 06:21:12 2008
@@ -11,29 +11,29 @@
 
 class FixWsComma(basefix.BaseFix):
 
-  explicit = True # The user must ask for this fixers
+    explicit = True # The user must ask for this fixers
 
-  PATTERN = """
-  any<(not(',') any)+ ',' ((not(',') any)+ ',')* [not(',') any]>
-  """
+    PATTERN = """
+    any<(not(',') any)+ ',' ((not(',') any)+ ',')* [not(',') any]>
+    """
 
-  COMMA = pytree.Leaf(token.COMMA, ",")
-  COLON = pytree.Leaf(token.COLON, ":")
-  SEPS = (COMMA, COLON)
+    COMMA = pytree.Leaf(token.COMMA, ",")
+    COLON = pytree.Leaf(token.COLON, ":")
+    SEPS = (COMMA, COLON)
 
-  def transform(self, node, results):
-    new = node.clone()
-    comma = False
-    for child in new.children:
-      if child in self.SEPS:
-        prefix = child.get_prefix()
-        if prefix.isspace() and "\n" not in prefix:
-          child.set_prefix("")
-        comma = True
-      else:
-        if comma:
-          prefix = child.get_prefix()
-          if not prefix:
-            child.set_prefix(" ")
+    def transform(self, node, results):
+        new = node.clone()
         comma = False
-    return new
+        for child in new.children:
+            if child in self.SEPS:
+                prefix = child.get_prefix()
+                if prefix.isspace() and "\n" not in prefix:
+                    child.set_prefix("")
+                comma = True
+            else:
+                if comma:
+                    prefix = child.get_prefix()
+                    if not prefix:
+                        child.set_prefix(" ")
+                comma = False
+        return new

Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_zip.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_zip.py	(original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_zip.py	Wed Mar 19 06:21:12 2008
@@ -33,7 +33,7 @@
             # If a future zip has been imported for this file, we won't
             # be making any modifications
             return
-            
+
         if in_special_context(node):
             return None
         new = node.clone()

Modified: sandbox/trunk/2to3/lib2to3/fixes/util.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/util.py	(original)
+++ sandbox/trunk/2to3/lib2to3/fixes/util.py	Wed Mar 19 06:21:12 2008
@@ -164,15 +164,15 @@
 
 def attr_chain(obj, attr):
     """Follow an attribute chain.
-    
+
     If you have a chain of objects where a.foo -> b, b.foo-> c, etc,
     use this to iterate over all objects in the chain. Iteration is
     terminated by getattr(x, attr) is None.
-    
+
     Args:
         obj: the starting object
         attr: the name of the chaining attribute
-    
+
     Yields:
         Each successive object in the chain.
     """
@@ -279,8 +279,8 @@
         elif child.type == syms.simple_stmt:
             ret = find_binding(name, child, package)
         elif child.type == syms.expr_stmt:
-                if _find(name, child.children[0]):
-                    ret = child
+            if _find(name, child.children[0]):
+                ret = child
 
         if ret:
             if not package:

Modified: sandbox/trunk/2to3/lib2to3/refactor.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/refactor.py	(original)
+++ sandbox/trunk/2to3/lib2to3/refactor.py	Wed Mar 19 06:21:12 2008
@@ -118,7 +118,7 @@
 
     def get_fixers(self):
         """Inspects the options to load the requested patterns and handlers.
-        
+
         Returns:
           (pre_order, post_order), where pre_order is the list of fixers that
           want a pre-order AST traversal, and post_order is the list that want
@@ -232,11 +232,11 @@
 
     def refactor_string(self, data, name):
         """Refactor a given input string.
-        
+
         Args:
             data: a string holding the code to be refactored.
             name: a human-readable name for use in error/log messages.
-            
+
         Returns:
             An AST corresponding to the refactored input stream; None if
             there were errors during the parse.
@@ -274,12 +274,12 @@
 
     def refactor_tree(self, tree, name):
         """Refactors a parse tree (modifying the tree in place).
-        
+
         Args:
             tree: a pytree.Node instance representing the root of the tree
                   to be refactored.
             name: a human-readable name for this tree.
-        
+
         Returns:
             True if the tree was modified, False otherwise.
         """
@@ -296,13 +296,13 @@
 
     def traverse_by(self, fixers, traversal):
         """Traverse an AST, applying a set of fixers to each node.
-        
+
         This is a helper method for refactor_tree().
-        
+
         Args:
             fixers: a list of fixer instances.
             traversal: a generator that yields AST nodes.
-        
+
         Returns:
             None
         """
@@ -523,4 +523,4 @@
 
 
 if __name__ == "__main__":
-  sys.exit(main())
+    sys.exit(main())

Modified: sandbox/trunk/2to3/lib2to3/tests/benchmark.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/tests/benchmark.py	(original)
+++ sandbox/trunk/2to3/lib2to3/tests/benchmark.py	Wed Mar 19 06:21:12 2008
@@ -27,10 +27,10 @@
             setattr(self, k, v)
 
         self.verbose = False
-        
+
 def dummy_transform(*args, **kwargs):
     pass
-    
+
 ### Collect list of modules to match against
 ###############################################################################
 files = []

Modified: sandbox/trunk/2to3/lib2to3/tests/test_parser.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/tests/test_parser.py	(original)
+++ sandbox/trunk/2to3/lib2to3/tests/test_parser.py	Wed Mar 19 06:21:12 2008
@@ -109,7 +109,7 @@
         self.validate(s)
 
 
-# Adapted from Python 3's Lib/test/test_grammar.py:GrammarTests.testAtoms       
+# Adapted from Python 3's Lib/test/test_grammar.py:GrammarTests.testAtoms
 class TestSetLiteral(GrammarTest):
     def test_1(self):
         self.validate("""x = {'one'}""")

Modified: sandbox/trunk/2to3/lib2to3/tests/test_pytree.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/tests/test_pytree.py	(original)
+++ sandbox/trunk/2to3/lib2to3/tests/test_pytree.py	Wed Mar 19 06:21:12 2008
@@ -407,10 +407,10 @@
         pe = pytree.LeafPattern(1, "e", "pe")
         pf = pytree.LeafPattern(1, "f", "pf")
         pw = pytree.WildcardPattern([[pa, pb, pc], [pd, pe],
-	                             [pa, pb], [pc, pd], [pe, pf]],
+                                     [pa, pb], [pc, pd], [pe, pf]],
                                     min=1, max=4, name="pw")
         self.assertEqual([x[0] for x in pw.generate_matches(leaves)],
-	                 [3, 5, 2, 4, 6])
+                         [3, 5, 2, 4, 6])
         pr = pytree.NodePattern(type=1000, content=[pw], name="pr")
         matches = list(pytree.generate_matches([pr], [root]))
         self.assertEqual(len(matches), 1)


More information about the Python-checkins mailing list