Commits

Anonymous committed 5ecf9fd

All fixes conform to one common style, and added a few comments.

Comments (0)

Files changed (14)

lib3to2/fixes/fix_bool.py

-"""Fixer for __bool__ -> __nonzero__ methods."""
+"""
+Fixer for __bool__ -> __nonzero__ methods.
+"""
 
-# Local imports
 from lib2to3 import fixer_base
 from lib2to3.fixer_util import Name
 

lib3to2/fixes/fix_bytes.py

-"""Fixer that changes bytes to str.
-
+"""
+Fixer for bytes -> str.
 """
 
 import re
     def transform(self, node, results):
         new = node.clone()
         if node.type == token.NAME:
-            assert new.value == u'bytes'
+            assert new.value == u"bytes"
             new.value = u"str"
             return new
         elif node.type == token.STRING:

lib3to2/fixes/fix_funcattrs.py

-"""Fix function attribute names (f.__x__ -> f.func_x)."""
+"""
+Fixer for f.__x__ -> f.func_x.
+"""
 
-# Local imports
 from lib2to3 import fixer_base
 from lib2to3.fixer_util import Name
 

lib3to2/fixes/fix_getcwd.py

 """
-Fixer that changes os.getcwd() to os.getcwdu().
-Also warns about "from os import getcwd", suggesting the fixable form.
+Fixer for os.getcwd() -> os.getcwdu().
+Also warns about "from os import getcwd", suggesting the above form.
 """
 
 from lib2to3 import fixer_base
             name = results["name"]
             name.replace(Name(u"getcwdu", prefix=name.prefix))
         elif "bad" in results:
+            # Can't convert to getcwdu and then expect to catch every use.
             self.cannot_convert(node, "import os, use os.getcwd() instead.")
             return
         else:

lib3to2/fixes/fix_input.py

-"""Fixer that changes input(...) into raw_input(...)."""
-# Author: Joe Amenta
+"""
+Fixer for input(s) -> raw_input(s).
+"""
 
-# This fixer is a copy-paste of lib2to3/fixes/fix_raw_input.py by Andre Roberge,
-# with input and raw_input switched.
-
-# Local imports
 from lib2to3 import fixer_base
 from lib2to3.fixer_util import Name
 

lib3to2/fixes/fix_int.py

-"""Fixer that turns 'int' into 'long' everywhere.
+"""
+Fixer for int -> long.
 """
 
 from lib2to3 import fixer_base

lib3to2/fixes/fix_intern.py

-"""Fixer for sys.intern().
+"""
+Fixer for sys.intern(s) -> intern(s).
+"""
 
-sys.intern(s) -> intern(s)"""
-
-# Local imports
 from lib2to3 import pytree
 from lib2to3 import fixer_base
 from lib2to3.fixer_util import Name, BlankLine, find_binding, find_root

lib3to2/fixes/fix_memoryview.py

 """
-Fixer that changes memoryview(...) into buffer(...)
-Many memoryview(...) methods are invalid on buffer(...) objects,
-so the user must explicitly convert between them.
+Fixer for memoryview(s) -> buffer(s).
+Explicit because some memoryview methods are invalid on buffer objects.
 """
 
 from lib2to3 import fixer_base

lib3to2/fixes/fix_methodattrs.py

-"""Fix bound method attributes (method.im_? -> method.__?__).
+"""
+Fixer for method.im_X -> method.__X__.
 """
 
-# Local imports
 from lib2to3 import fixer_base
 from lib2to3.fixer_util import Name
 

lib3to2/fixes/fix_next.py

-"""Fixer for it.__next__() or next(it) -> it.next()"""
+"""
+Fixer for:
+it.__next__() -> it.next().
+next(it) -> it.next().
+"""
 
 from lib2to3.pgen2 import token
 from lib2to3.pygram import python_symbols as syms

lib3to2/fixes/fix_numliterals.py

 """
-Fixer that turns:
-1 into 1L
-0x1ed into __builtins__.long("1ed", 16)
-0b111101101 into __builtins__.long("111101101", 2)
-0o755 into 0755
+Fixer for:
+1 -> 1L
+0x1ed -> __builtins__.long("1ed", 16)
+0b111101101 -> __builtins__.long("111101101", 2)
+0o755 -> 0755
 """
 
 from lib2to3.pgen2 import token
 baseMAPPING = {'b':2, 'o':8, 'x':16}
 
 class FixNumliterals(fixer_base.BaseFix):
-    # We need to modify ALL numeric literals.
+    # We need to modify all numeric literals except floats, complex.
 
     def base(self, literal):
-        """Returns the base of a literal."""
+        """Returns the base of a valid py3k literal."""
         literal = literal.strip()
         if not literal.startswith(u"0"):
             return 10
             return baseMAPPING[literal[1]]
 
     def unmatch(self, node):
+        """Don't match complex numbers or floats."""
         for bad in u"jJ+-.":
             if bad in node.value: return bad
         
     def match(self, node):
         return ((node.type == token.NUMBER) and not self.unmatch(node))
     def transform(self, node, results):
+        """
+        Call __builtins__.long() with the value and the base of the value.
+        This works because 0b10 is int("10", 2), 0o10 is int("10", 8), etc.
+        """
+        
         val = node.value
         base = self.base
         if val.isdigit() and base(val) == 10:
             assert val.startswith(u"0") and val[1] in u"bxBX", \
                                            "Invalid format for numeric literal"
             base = Number(base(val), prefix=u" ")
+            # __builtins__.long
             func_name = Node(syms.power, Attr(Name(u"__builtins__"), \
                              Name(u"long")))
-            import sys
+            # ("...", [2 or 16])
             func_args = [String(u"".join((u"\"", val.strip()[2:], u"\""))), \
                          Comma(), base]
             new_node = Call(func_name, func_args, node.prefix)

lib3to2/fixes/fix_print.py

 """
-Fixer for print.
-Currently, this can be seen as a "placeholder":  All it does is add a
-future_stmt to the top that includes the print_function, so the resulting code
-is only compatible with 2.6+.
+Fixer for print: from __future__ import print_function.
+"Placeholder": In the future, this will transform print into a print statement
 """
 
 from lib2to3 import fixer_base, pytree

lib3to2/fixes/fix_range.py

-"""Fixer that changes range(...) into xrange(...)."""
+"""
+Fixer for range(s) -> xrange(s).
+"""
 
-# Local imports
 from lib2to3 import fixer_base
 from lib2to3.fixer_util import Name
 

lib3to2/fixes/fix_str.py

-"""Fixer that changes str to unicode, chr to unichr, and "..." into u"...".
-
+"""
+Fixer for:
+str -> unicode
+chr -> unichr
+"spam" -> u"spam"
 """
 
 import re
     def transform(self, node, results):
         new = node.clone()
         if node.type == token.STRING:
+            #Simply add u to the beginning of the literal.
             if _literal_re.match(new.value):
                 new.value = u"u" + new.value
                 return new