[Python-checkins] r73861 - in sandbox/trunk/2to3: README lib2to3/fixes/fix_operator.py

benjamin.peterson python-checkins at python.org
Sun Jul 5 16:15:53 CEST 2009


Author: benjamin.peterson
Date: Sun Jul  5 16:15:53 2009
New Revision: 73861

Log:
cleanup and use unicode where appropiate

Modified:
   sandbox/trunk/2to3/README
   sandbox/trunk/2to3/lib2to3/fixes/fix_operator.py

Modified: sandbox/trunk/2to3/README
==============================================================================
--- sandbox/trunk/2to3/README	(original)
+++ sandbox/trunk/2to3/README	Sun Jul  5 16:15:53 2009
@@ -1,7 +1,7 @@
 Abstract
 ========
 
-A refactoring tool for converting Python 2.x code to 3.0.
+A refactoring tool for converting Python 2.x code to 3.x.
 
 This is a work in progress! Bugs should be reported to http://bugs.python.org/
 under the "2to3" category.
@@ -11,12 +11,9 @@
 =============
 
 Run ``./2to3`` to convert stdin (``-``), files or directories given as
-arguments.  By default, the tool outputs a unified diff-formatted patch on
-standard output and a "what was changed" summary on standard error, but the
-``-w`` option can be given to write back converted files, creating
-``.bak``-named backup files.
+arguments.
 
-2to3 must be run with at least Python 2.5. The intended path for migrating to
+2to3 must be run with at least Python 2.6. The intended path for migrating to
 Python 3.x is to first migrate to 2.6 (in order to take advantage of Python
 2.6's runtime compatibility checks).
 
@@ -30,15 +27,15 @@
 lib2to3/patcomp.py            - pattern compiler
 lib2to3/pytree.py             - parse tree nodes (not specific to Python, despite the name!)
 lib2to3/pygram.py             - code specific to the Python grammar
-example.py                    - example input for play.py and fix_*.py
-find_pattern.py               - script to help determine the PATTERN for a new fix
+scripts/example.py            - example input for play.py and fix_*.py
+scripts/find_pattern.py       - script to help determine the PATTERN for a new fix
 lib2to3/Grammar.txt           - Python grammar input (accepts 2.x and 3.x syntax)
 lib2to3/Grammar.pickle        - pickled grammar tables (generated file, not in subversion)
 lib2to3/PatternGrammar.txt    - grammar for the pattern language used by patcomp.py
 lib2to3/PatternGrammar.pickle - pickled pattern grammar tables (generated file)
 lib2to3/pgen2/                - Parser generator and driver ([1]_, [2]_)
 lib2to3/fixes/                - Individual transformations
-lib2to3tests/                 - Test files for pytree, fixers, grammar, etc
+lib2to3/tests/                - Test files for pytree, fixers, grammar, etc
 
 
 Capabilities

Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_operator.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_operator.py	(original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_operator.py	Sun Jul  5 16:15:53 2009
@@ -14,28 +14,27 @@
     func = "'(' func=any ')'"
     PATTERN = """
               power< module='operator'
-                trailer< '.' %(methods)s > trailer< %(func)s > >
+                trailer< '.' {methods} > trailer< {func} > >
               |
-              power< %(methods)s trailer< %(func)s > >
-              """ % locals()
+              power< {methods} trailer< {func} > >
+              """.format(methods=methods, func=func)
 
     def transform(self, node, results):
         method = results["method"][0]
 
-        if method.value == "sequenceIncludes":
+        if method.value == u"sequenceIncludes":
             if "module" not in results:
                 # operator may not be in scope, so we can't make a change.
                 self.warning(node, "You should use operator.contains here.")
             else:
-                method.value = "contains"
+                method.value = u"contains"
                 method.changed()
-                return node
-        elif method.value == "isCallable":
+        elif method.value == u"isCallable":
             if "module" not in results:
                 self.warning(node,
                              "You should use hasattr(%s, '__call__') here." %
                              results["func"].value)
             else:
                 func = results["func"]
-                args = [func.clone(), String(", "), String("'__call__'")]
-                return Call(Name("hasattr"), args, prefix=node.get_prefix())
+                args = [func.clone(), String(u", "), String(u"'__call__'")]
+                return Call(Name(u"hasattr"), args, prefix=node.get_prefix())


More information about the Python-checkins mailing list