[Python-checkins] r67769 - in sandbox/trunk/2to3/lib2to3: fixer_base.py fixer_util.py fixes/fix_apply.py fixes/fix_has_key.py fixes/fix_repr.py pygram.py
benjamin.peterson
python-checkins at python.org
Sun Dec 14 21:59:11 CET 2008
Author: benjamin.peterson
Date: Sun Dec 14 21:59:10 2008
New Revision: 67769
Log:
parenthesize doesn't belong in pygram or FixerBase
Modified:
sandbox/trunk/2to3/lib2to3/fixer_base.py
sandbox/trunk/2to3/lib2to3/fixer_util.py
sandbox/trunk/2to3/lib2to3/fixes/fix_apply.py
sandbox/trunk/2to3/lib2to3/fixes/fix_has_key.py
sandbox/trunk/2to3/lib2to3/fixes/fix_repr.py
sandbox/trunk/2to3/lib2to3/pygram.py
Modified: sandbox/trunk/2to3/lib2to3/fixer_base.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixer_base.py (original)
+++ sandbox/trunk/2to3/lib2to3/fixer_base.py Sun Dec 14 21:59:10 2008
@@ -94,10 +94,6 @@
"""
raise NotImplementedError()
- def parenthesize(self, node):
- """Wrapper around pygram.parenthesize()."""
- return pygram.parenthesize(node)
-
def new_name(self, template="xxx_todo_changeme"):
"""Return a string suitable for use as an identifier
Modified: sandbox/trunk/2to3/lib2to3/fixer_util.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixer_util.py (original)
+++ sandbox/trunk/2to3/lib2to3/fixer_util.py Sun Dec 14 21:59:10 2008
@@ -158,6 +158,9 @@
### Misc
###########################################################
+def parenthesize(node):
+ return Node(syms.atom, [LParen(), node, RParen()])
+
consuming_calls = set(["sorted", "list", "set", "any", "all", "tuple", "sum",
"min", "max"])
Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_apply.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_apply.py (original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_apply.py Sun Dec 14 21:59:10 2008
@@ -9,7 +9,7 @@
from .. import pytree
from ..pgen2 import token
from .. import fixer_base
-from ..fixer_util import Call, Comma
+from ..fixer_util import Call, Comma, parenthesize
class FixApply(fixer_base.BaseFix):
@@ -39,7 +39,7 @@
(func.type != syms.power or
func.children[-2].type == token.DOUBLESTAR)):
# Need to parenthesize
- func = self.parenthesize(func)
+ func = parenthesize(func)
func.set_prefix("")
args = args.clone()
args.set_prefix("")
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 Sun Dec 14 21:59:10 2008
@@ -33,7 +33,7 @@
from .. import pytree
from ..pgen2 import token
from .. import fixer_base
-from ..fixer_util import Name
+from ..fixer_util import Name, parenthesize
class FixHasKey(fixer_base.BaseFix):
@@ -86,7 +86,7 @@
after = [n.clone() for n in after]
if arg.type in (syms.comparison, syms.not_test, syms.and_test,
syms.or_test, syms.test, syms.lambdef, syms.argument):
- arg = self.parenthesize(arg)
+ arg = parenthesize(arg)
if len(before) == 1:
before = before[0]
else:
@@ -98,12 +98,12 @@
n_op = pytree.Node(syms.comp_op, (n_not, n_op))
new = pytree.Node(syms.comparison, (arg, n_op, before))
if after:
- new = self.parenthesize(new)
+ new = parenthesize(new)
new = pytree.Node(syms.power, (new,) + tuple(after))
if node.parent.type in (syms.comparison, syms.expr, syms.xor_expr,
syms.and_expr, syms.shift_expr,
syms.arith_expr, syms.term,
syms.factor, syms.power):
- new = self.parenthesize(new)
+ new = parenthesize(new)
new.set_prefix(prefix)
return new
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 Sun Dec 14 21:59:10 2008
@@ -5,7 +5,7 @@
# Local imports
from .. import fixer_base
-from ..fixer_util import Call, Name
+from ..fixer_util import Call, Name, parenthesize
class FixRepr(fixer_base.BaseFix):
@@ -18,5 +18,5 @@
expr = results["expr"].clone()
if expr.type == self.syms.testlist1:
- expr = self.parenthesize(expr)
+ expr = parenthesize(expr)
return Call(Name("repr"), [expr], prefix=node.get_prefix())
Modified: sandbox/trunk/2to3/lib2to3/pygram.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/pygram.py (original)
+++ sandbox/trunk/2to3/lib2to3/pygram.py Sun Dec 14 21:59:10 2008
@@ -29,10 +29,3 @@
python_grammar = driver.load_grammar(_GRAMMAR_FILE)
python_symbols = Symbols(python_grammar)
-
-
-def parenthesize(node):
- return pytree.Node(python_symbols.atom,
- (pytree.Leaf(token.LPAR, "("),
- node,
- pytree.Leaf(token.RPAR, ")")))
More information about the Python-checkins
mailing list