summaryrefslogtreecommitdiffstats
path: root/Lib/lib2to3/fixes
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/lib2to3/fixes')
-rw-r--r--Lib/lib2to3/fixes/fix_apply.py10
-rw-r--r--Lib/lib2to3/fixes/fix_basestring.py2
-rw-r--r--Lib/lib2to3/fixes/fix_buffer.py4
-rw-r--r--Lib/lib2to3/fixes/fix_callable.py2
-rw-r--r--Lib/lib2to3/fixes/fix_dict.py6
-rw-r--r--Lib/lib2to3/fixes/fix_except.py16
-rw-r--r--Lib/lib2to3/fixes/fix_exec.py4
-rw-r--r--Lib/lib2to3/fixes/fix_execfile.py4
-rw-r--r--Lib/lib2to3/fixes/fix_filter.py4
-rw-r--r--Lib/lib2to3/fixes/fix_funcattrs.py2
-rw-r--r--Lib/lib2to3/fixes/fix_future.py2
-rw-r--r--Lib/lib2to3/fixes/fix_getcwdu.py2
-rw-r--r--Lib/lib2to3/fixes/fix_has_key.py6
-rw-r--r--Lib/lib2to3/fixes/fix_idioms.py20
-rw-r--r--Lib/lib2to3/fixes/fix_import.py2
-rw-r--r--Lib/lib2to3/fixes/fix_imports.py4
-rw-r--r--Lib/lib2to3/fixes/fix_input.py4
-rw-r--r--Lib/lib2to3/fixes/fix_intern.py2
-rw-r--r--Lib/lib2to3/fixes/fix_isinstance.py2
-rw-r--r--Lib/lib2to3/fixes/fix_itertools.py4
-rw-r--r--Lib/lib2to3/fixes/fix_itertools_imports.py2
-rw-r--r--Lib/lib2to3/fixes/fix_long.py2
-rw-r--r--Lib/lib2to3/fixes/fix_map.py6
-rw-r--r--Lib/lib2to3/fixes/fix_metaclass.py16
-rw-r--r--Lib/lib2to3/fixes/fix_methodattrs.py2
-rw-r--r--Lib/lib2to3/fixes/fix_ne.py3
-rw-r--r--Lib/lib2to3/fixes/fix_next.py9
-rw-r--r--Lib/lib2to3/fixes/fix_nonzero.py2
-rw-r--r--Lib/lib2to3/fixes/fix_numliterals.py2
-rw-r--r--Lib/lib2to3/fixes/fix_paren.py4
-rw-r--r--Lib/lib2to3/fixes/fix_print.py10
-rw-r--r--Lib/lib2to3/fixes/fix_raise.py12
-rw-r--r--Lib/lib2to3/fixes/fix_raw_input.py2
-rw-r--r--Lib/lib2to3/fixes/fix_renames.py2
-rw-r--r--Lib/lib2to3/fixes/fix_repr.py2
-rw-r--r--Lib/lib2to3/fixes/fix_set_literal.py6
-rw-r--r--Lib/lib2to3/fixes/fix_standarderror.py2
-rw-r--r--Lib/lib2to3/fixes/fix_sys_exc.py6
-rw-r--r--Lib/lib2to3/fixes/fix_throw.py4
-rw-r--r--Lib/lib2to3/fixes/fix_tuple_params.py14
-rw-r--r--Lib/lib2to3/fixes/fix_types.py2
-rw-r--r--Lib/lib2to3/fixes/fix_unicode.py19
-rw-r--r--Lib/lib2to3/fixes/fix_urllib.py6
-rw-r--r--Lib/lib2to3/fixes/fix_ws_comma.py8
-rw-r--r--Lib/lib2to3/fixes/fix_xrange.py4
-rw-r--r--Lib/lib2to3/fixes/fix_xreadlines.py2
-rw-r--r--Lib/lib2to3/fixes/fix_zip.py4
47 files changed, 125 insertions, 130 deletions
diff --git a/Lib/lib2to3/fixes/fix_apply.py b/Lib/lib2to3/fixes/fix_apply.py
index 953b9b1..6d1c5d9 100644
--- a/Lib/lib2to3/fixes/fix_apply.py
+++ b/Lib/lib2to3/fixes/fix_apply.py
@@ -33,25 +33,25 @@ class FixApply(fixer_base.BaseFix):
func = results["func"]
args = results["args"]
kwds = results.get("kwds")
- prefix = node.get_prefix()
+ prefix = node.prefix
func = func.clone()
if (func.type not in (token.NAME, syms.atom) and
(func.type != syms.power or
func.children[-2].type == token.DOUBLESTAR)):
# Need to parenthesize
func = parenthesize(func)
- func.set_prefix("")
+ func.prefix = ""
args = args.clone()
- args.set_prefix("")
+ args.prefix = ""
if kwds is not None:
kwds = kwds.clone()
- kwds.set_prefix("")
+ kwds.prefix = ""
l_newargs = [pytree.Leaf(token.STAR, u"*"), args]
if kwds is not None:
l_newargs.extend([Comma(),
pytree.Leaf(token.DOUBLESTAR, u"**"),
kwds])
- l_newargs[-2].set_prefix(u" ") # that's the ** token
+ l_newargs[-2].prefix = u" " # that's the ** token
# XXX Sometimes we could be cleverer, e.g. apply(f, (x, y) + t)
# can be translated into f(x, y, *t) instead of f(*(x, y) + t)
#new = pytree.Node(syms.power, (func, ArgList(l_newargs)))
diff --git a/Lib/lib2to3/fixes/fix_basestring.py b/Lib/lib2to3/fixes/fix_basestring.py
index 138e732..0de6c26 100644
--- a/Lib/lib2to3/fixes/fix_basestring.py
+++ b/Lib/lib2to3/fixes/fix_basestring.py
@@ -10,4 +10,4 @@ class FixBasestring(fixer_base.BaseFix):
PATTERN = "'basestring'"
def transform(self, node, results):
- return Name(u"str", prefix=node.get_prefix())
+ return Name(u"str", prefix=node.prefix)
diff --git a/Lib/lib2to3/fixes/fix_buffer.py b/Lib/lib2to3/fixes/fix_buffer.py
index 34cc168..1c1c4a1 100644
--- a/Lib/lib2to3/fixes/fix_buffer.py
+++ b/Lib/lib2to3/fixes/fix_buffer.py
@@ -13,9 +13,9 @@ class FixBuffer(fixer_base.BaseFix):
explicit = True # The user must ask for this fixer
PATTERN = """
- power< name='buffer' trailer< '(' [any] ')' > >
+ power< name='buffer' trailer< '(' [any] ')' > any* >
"""
def transform(self, node, results):
name = results["name"]
- name.replace(Name(u"memoryview", prefix=name.get_prefix()))
+ name.replace(Name(u"memoryview", prefix=name.prefix))
diff --git a/Lib/lib2to3/fixes/fix_callable.py b/Lib/lib2to3/fixes/fix_callable.py
index 4de3f66..03c8923 100644
--- a/Lib/lib2to3/fixes/fix_callable.py
+++ b/Lib/lib2to3/fixes/fix_callable.py
@@ -28,4 +28,4 @@ class FixCallable(fixer_base.BaseFix):
func = results["func"]
args = [func.clone(), String(u', '), String(u"'__call__'")]
- return Call(Name(u"hasattr"), args, prefix=node.get_prefix())
+ return Call(Name(u"hasattr"), args, prefix=node.prefix)
diff --git a/Lib/lib2to3/fixes/fix_dict.py b/Lib/lib2to3/fixes/fix_dict.py
index b0b9de0..098de7c 100644
--- a/Lib/lib2to3/fixes/fix_dict.py
+++ b/Lib/lib2to3/fixes/fix_dict.py
@@ -61,15 +61,15 @@ class FixDict(fixer_base.BaseFix):
args = head + [pytree.Node(syms.trailer,
[Dot(),
Name(method_name,
- prefix=method.get_prefix())]),
+ prefix=method.prefix)]),
results["parens"].clone()]
new = pytree.Node(syms.power, args)
if not special:
- new.set_prefix(u"")
+ new.prefix = u""
new = Call(Name(isiter and u"iter" or u"list"), [new])
if tail:
new = pytree.Node(syms.power, [new] + tail)
- new.set_prefix(node.get_prefix())
+ new.prefix = node.prefix
return new
P1 = "power< func=NAME trailer< '(' node=any ')' > any* >"
diff --git a/Lib/lib2to3/fixes/fix_except.py b/Lib/lib2to3/fixes/fix_except.py
index edac97e..8118058 100644
--- a/Lib/lib2to3/fixes/fix_except.py
+++ b/Lib/lib2to3/fixes/fix_except.py
@@ -36,11 +36,11 @@ def find_excepts(nodes):
class FixExcept(fixer_base.BaseFix):
PATTERN = """
- try_stmt< 'try' ':' suite
- cleanup=(except_clause ':' suite)+
- tail=(['except' ':' suite]
- ['else' ':' suite]
- ['finally' ':' suite]) >
+ try_stmt< 'try' ':' (simple_stmt | suite)
+ cleanup=(except_clause ':' (simple_stmt | suite))+
+ tail=(['except' ':' (simple_stmt | suite)]
+ ['else' ':' (simple_stmt | suite)]
+ ['finally' ':' (simple_stmt | suite)]) >
"""
def transform(self, node, results):
@@ -58,7 +58,7 @@ class FixExcept(fixer_base.BaseFix):
# Generate a new N for the except clause
new_N = Name(self.new_name(), prefix=u" ")
target = N.clone()
- target.set_prefix(u"")
+ target.prefix = u""
N.replace(new_N)
new_N = new_N.clone()
@@ -82,10 +82,10 @@ class FixExcept(fixer_base.BaseFix):
for child in reversed(suite_stmts[:i]):
e_suite.insert_child(0, child)
e_suite.insert_child(i, assign)
- elif N.get_prefix() == u"":
+ elif N.prefix == u"":
# No space after a comma is legal; no space after "as",
# not so much.
- N.set_prefix(u" ")
+ N.prefix = u" "
#TODO(cwinter) fix this when children becomes a smart list
children = [c.clone() for c in node.children[:3]] + try_cleanup + tail
diff --git a/Lib/lib2to3/fixes/fix_exec.py b/Lib/lib2to3/fixes/fix_exec.py
index adc8eb0..121431c 100644
--- a/Lib/lib2to3/fixes/fix_exec.py
+++ b/Lib/lib2to3/fixes/fix_exec.py
@@ -30,10 +30,10 @@ class FixExec(fixer_base.BaseFix):
b = results.get("b")
c = results.get("c")
args = [a.clone()]
- args[0].set_prefix("")
+ args[0].prefix = ""
if b is not None:
args.extend([Comma(), b.clone()])
if c is not None:
args.extend([Comma(), c.clone()])
- return Call(Name(u"exec"), args, prefix=node.get_prefix())
+ return Call(Name(u"exec"), args, prefix=node.prefix)
diff --git a/Lib/lib2to3/fixes/fix_execfile.py b/Lib/lib2to3/fixes/fix_execfile.py
index d8997cf..38d6abc 100644
--- a/Lib/lib2to3/fixes/fix_execfile.py
+++ b/Lib/lib2to3/fixes/fix_execfile.py
@@ -38,7 +38,7 @@ class FixExecfile(fixer_base.BaseFix):
# Wrap the open call in a compile call. This is so the filename will be
# preserved in the execed code.
filename_arg = filename.clone()
- filename_arg.set_prefix(u" ")
+ filename_arg.prefix = u" "
exec_str = String(u"'exec'", u" ")
compile_args = open_expr + [Comma(), filename_arg, Comma(), exec_str]
compile_call = Call(Name(u"compile"), compile_args, u"")
@@ -48,4 +48,4 @@ class FixExecfile(fixer_base.BaseFix):
args.extend([Comma(), globals.clone()])
if locals is not None:
args.extend([Comma(), locals.clone()])
- return Call(Name(u"exec"), args, prefix=node.get_prefix())
+ return Call(Name(u"exec"), args, prefix=node.prefix)
diff --git a/Lib/lib2to3/fixes/fix_filter.py b/Lib/lib2to3/fixes/fix_filter.py
index 946be3e..0e92b14 100644
--- a/Lib/lib2to3/fixes/fix_filter.py
+++ b/Lib/lib2to3/fixes/fix_filter.py
@@ -69,7 +69,7 @@ class FixFilter(fixer_base.ConditionalFix):
if in_special_context(node):
return None
new = node.clone()
- new.set_prefix(u"")
+ new.prefix = u""
new = Call(Name(u"list"), [new])
- new.set_prefix(node.get_prefix())
+ new.prefix = node.prefix
return new
diff --git a/Lib/lib2to3/fixes/fix_funcattrs.py b/Lib/lib2to3/fixes/fix_funcattrs.py
index 680cb35..5d1ba8c 100644
--- a/Lib/lib2to3/fixes/fix_funcattrs.py
+++ b/Lib/lib2to3/fixes/fix_funcattrs.py
@@ -16,4 +16,4 @@ class FixFuncattrs(fixer_base.BaseFix):
def transform(self, node, results):
attr = results["attr"][0]
attr.replace(Name((u"__%s__" % attr.value[5:]),
- prefix=attr.get_prefix()))
+ prefix=attr.prefix))
diff --git a/Lib/lib2to3/fixes/fix_future.py b/Lib/lib2to3/fixes/fix_future.py
index a032e88..861e13c 100644
--- a/Lib/lib2to3/fixes/fix_future.py
+++ b/Lib/lib2to3/fixes/fix_future.py
@@ -16,5 +16,5 @@ class FixFuture(fixer_base.BaseFix):
def transform(self, node, results):
new = BlankLine()
- new.prefix = node.get_prefix()
+ new.prefix = node.prefix
return new
diff --git a/Lib/lib2to3/fixes/fix_getcwdu.py b/Lib/lib2to3/fixes/fix_getcwdu.py
index 1e1e2fe..a5b5aa3 100644
--- a/Lib/lib2to3/fixes/fix_getcwdu.py
+++ b/Lib/lib2to3/fixes/fix_getcwdu.py
@@ -15,4 +15,4 @@ class FixGetcwdu(fixer_base.BaseFix):
def transform(self, node, results):
name = results["name"]
- name.replace(Name(u"getcwd", prefix=name.get_prefix()))
+ name.replace(Name(u"getcwd", prefix=name.prefix))
diff --git a/Lib/lib2to3/fixes/fix_has_key.py b/Lib/lib2to3/fixes/fix_has_key.py
index ec7210a..0915a36 100644
--- a/Lib/lib2to3/fixes/fix_has_key.py
+++ b/Lib/lib2to3/fixes/fix_has_key.py
@@ -78,7 +78,7 @@ class FixHasKey(fixer_base.BaseFix):
return None
negation = results.get("negation")
anchor = results["anchor"]
- prefix = node.get_prefix()
+ prefix = node.prefix
before = [n.clone() for n in results["before"]]
arg = results["arg"].clone()
after = results.get("after")
@@ -91,7 +91,7 @@ class FixHasKey(fixer_base.BaseFix):
before = before[0]
else:
before = pytree.Node(syms.power, before)
- before.set_prefix(u" ")
+ before.prefix = u" "
n_op = Name(u"in", prefix=u" ")
if negation:
n_not = Name(u"not", prefix=u" ")
@@ -105,5 +105,5 @@ class FixHasKey(fixer_base.BaseFix):
syms.arith_expr, syms.term,
syms.factor, syms.power):
new = parenthesize(new)
- new.set_prefix(prefix)
+ new.prefix = prefix
return new
diff --git a/Lib/lib2to3/fixes/fix_idioms.py b/Lib/lib2to3/fixes/fix_idioms.py
index 6977c7f..71dff5b 100644
--- a/Lib/lib2to3/fixes/fix_idioms.py
+++ b/Lib/lib2to3/fixes/fix_idioms.py
@@ -101,18 +101,18 @@ class FixIdioms(fixer_base.BaseFix):
def transform_isinstance(self, node, results):
x = results["x"].clone() # The thing inside of type()
T = results["T"].clone() # The type being compared against
- x.set_prefix("")
- T.set_prefix(" ")
- test = Call(Name("isinstance"), [x, Comma(), T])
+ x.prefix = u""
+ T.prefix = u" "
+ test = Call(Name(u"isinstance"), [x, Comma(), T])
if "n" in results:
- test.set_prefix(u" ")
+ test.prefix = u" "
test = Node(syms.not_test, [Name(u"not"), test])
- test.set_prefix(node.get_prefix())
+ test.prefix = node.prefix
return test
def transform_while(self, node, results):
one = results["while"]
- one.replace(Name(u"True", prefix=one.get_prefix()))
+ one.replace(Name(u"True", prefix=one.prefix))
def transform_sort(self, node, results):
sort_stmt = results["sort"]
@@ -121,14 +121,14 @@ class FixIdioms(fixer_base.BaseFix):
simple_expr = results.get("expr")
if list_call:
- list_call.replace(Name(u"sorted", prefix=list_call.get_prefix()))
+ list_call.replace(Name(u"sorted", prefix=list_call.prefix))
elif simple_expr:
new = simple_expr.clone()
- new.set_prefix(u"")
+ new.prefix = u""
simple_expr.replace(Call(Name(u"sorted"), [new],
- prefix=simple_expr.get_prefix()))
+ prefix=simple_expr.prefix))
else:
raise RuntimeError("should not have reached here")
sort_stmt.remove()
if next_stmt:
- next_stmt[0].set_prefix(sort_stmt.get_prefix())
+ next_stmt[0].prefix = sort_stmt.prefix
diff --git a/Lib/lib2to3/fixes/fix_import.py b/Lib/lib2to3/fixes/fix_import.py
index 50ffb41..0a98cc3 100644
--- a/Lib/lib2to3/fixes/fix_import.py
+++ b/Lib/lib2to3/fixes/fix_import.py
@@ -73,7 +73,7 @@ class FixImport(fixer_base.BaseFix):
return
new = FromImport('.', [imp])
- new.set_prefix(node.get_prefix())
+ new.prefix = node.prefix
return new
def probably_a_local_import(self, imp_name):
diff --git a/Lib/lib2to3/fixes/fix_imports.py b/Lib/lib2to3/fixes/fix_imports.py
index 3236a08..00f0a75 100644
--- a/Lib/lib2to3/fixes/fix_imports.py
+++ b/Lib/lib2to3/fixes/fix_imports.py
@@ -124,7 +124,7 @@ class FixImports(fixer_base.BaseFix):
if import_mod:
mod_name = import_mod.value
new_name = unicode(self.mapping[mod_name])
- import_mod.replace(Name(new_name, prefix=import_mod.get_prefix()))
+ import_mod.replace(Name(new_name, prefix=import_mod.prefix))
if "name_import" in results:
# If it's not a "from x import x, y" or "import x as y" import,
# marked its usage to be replaced.
@@ -142,4 +142,4 @@ class FixImports(fixer_base.BaseFix):
bare_name = results["bare_with_attr"][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.prefix))
diff --git a/Lib/lib2to3/fixes/fix_input.py b/Lib/lib2to3/fixes/fix_input.py
index 3e330f6..291cadf 100644
--- a/Lib/lib2to3/fixes/fix_input.py
+++ b/Lib/lib2to3/fixes/fix_input.py
@@ -22,5 +22,5 @@ class FixInput(fixer_base.BaseFix):
return
new = node.clone()
- new.set_prefix(u"")
- return Call(Name(u"eval"), [new], prefix=node.get_prefix())
+ new.prefix = u""
+ return Call(Name(u"eval"), [new], prefix=node.prefix)
diff --git a/Lib/lib2to3/fixes/fix_intern.py b/Lib/lib2to3/fixes/fix_intern.py
index 46e5239..67f98ef 100644
--- a/Lib/lib2to3/fixes/fix_intern.py
+++ b/Lib/lib2to3/fixes/fix_intern.py
@@ -39,6 +39,6 @@ class FixIntern(fixer_base.BaseFix):
[results["lpar"].clone(),
newarglist,
results["rpar"].clone()])] + after)
- new.set_prefix(node.get_prefix())
+ new.prefix = node.prefix
touch_import(None, u'sys', node)
return new
diff --git a/Lib/lib2to3/fixes/fix_isinstance.py b/Lib/lib2to3/fixes/fix_isinstance.py
index 295577a..c720a83 100644
--- a/Lib/lib2to3/fixes/fix_isinstance.py
+++ b/Lib/lib2to3/fixes/fix_isinstance.py
@@ -45,7 +45,7 @@ class FixIsinstance(fixer_base.BaseFix):
del new_args[-1]
if len(new_args) == 1:
atom = testlist.parent
- new_args[0].set_prefix(atom.get_prefix())
+ new_args[0].prefix = atom.prefix
atom.replace(new_args[0])
else:
args[:] = new_args
diff --git a/Lib/lib2to3/fixes/fix_itertools.py b/Lib/lib2to3/fixes/fix_itertools.py
index d781cf3..77b3a01 100644
--- a/Lib/lib2to3/fixes/fix_itertools.py
+++ b/Lib/lib2to3/fixes/fix_itertools.py
@@ -30,12 +30,12 @@ class FixItertools(fixer_base.BaseFix):
if 'it' in results and func.value != u'ifilterfalse':
dot, it = (results['dot'], results['it'])
# Remove the 'itertools'
- prefix = it.get_prefix()
+ prefix = it.prefix
it.remove()
# Replace the node wich contains ('.', 'function') with the
# function (to be consistant with the second part of the pattern)
dot.remove()
func.parent.replace(func)
- prefix = prefix or func.get_prefix()
+ prefix = prefix or func.prefix
func.replace(Name(func.value[1:], prefix=prefix))
diff --git a/Lib/lib2to3/fixes/fix_itertools_imports.py b/Lib/lib2to3/fixes/fix_itertools_imports.py
index 4df2301..ab43dcd 100644
--- a/Lib/lib2to3/fixes/fix_itertools_imports.py
+++ b/Lib/lib2to3/fixes/fix_itertools_imports.py
@@ -46,7 +46,7 @@ class FixItertoolsImports(fixer_base.BaseFix):
# If there are no imports left, just get rid of the entire statement
if not (imports.children or getattr(imports, 'value', None)) or \
imports.parent is None:
- p = node.get_prefix()
+ p = node.prefix
node = BlankLine()
node.prefix = p
return node
diff --git a/Lib/lib2to3/fixes/fix_long.py b/Lib/lib2to3/fixes/fix_long.py
index 3232902..73aba48 100644
--- a/Lib/lib2to3/fixes/fix_long.py
+++ b/Lib/lib2to3/fixes/fix_long.py
@@ -18,5 +18,5 @@ class FixLong(fixer_base.BaseFix):
def transform(self, node, results):
if is_probably_builtin(node):
new = self.static_int.clone()
- new.set_prefix(node.get_prefix())
+ new.prefix = node.prefix
return new
diff --git a/Lib/lib2to3/fixes/fix_map.py b/Lib/lib2to3/fixes/fix_map.py
index c57154d..8b55b56 100644
--- a/Lib/lib2to3/fixes/fix_map.py
+++ b/Lib/lib2to3/fixes/fix_map.py
@@ -63,7 +63,7 @@ class FixMap(fixer_base.ConditionalFix):
if node.parent.type == syms.simple_stmt:
self.warning(node, "You should use a for loop here")
new = node.clone()
- new.set_prefix(u"")
+ new.prefix = u""
new = Call(Name(u"list"), [new])
elif "map_lambda" in results:
new = ListComp(results.get("xp").clone(),
@@ -76,7 +76,7 @@ class FixMap(fixer_base.ConditionalFix):
if in_special_context(node):
return None
new = node.clone()
- new.set_prefix(u"")
+ new.prefix = u""
new = Call(Name(u"list"), [new])
- new.set_prefix(node.get_prefix())
+ new.prefix = node.prefix
return new
diff --git a/Lib/lib2to3/fixes/fix_metaclass.py b/Lib/lib2to3/fixes/fix_metaclass.py
index 3b1b3ea..ed8e5d5 100644
--- a/Lib/lib2to3/fixes/fix_metaclass.py
+++ b/Lib/lib2to3/fixes/fix_metaclass.py
@@ -89,7 +89,7 @@ def fixup_simple_stmt(parent, i, stmt_node):
parent.insert_child(i, new_stmt)
new_leaf1 = new_stmt.children[0].children[0]
old_leaf1 = stmt_node.children[0].children[0]
- new_leaf1.set_prefix(old_leaf1.get_prefix())
+ new_leaf1.prefix = old_leaf1.prefix
def remove_trailing_newline(node):
@@ -136,7 +136,7 @@ def fixup_indent(suite):
node = kids.pop()
if isinstance(node, Leaf) and node.type != token.DEDENT:
if node.prefix:
- node.set_prefix('')
+ node.prefix = u''
return
else:
kids.extend(node.children[::-1])
@@ -191,19 +191,19 @@ class FixMetaclass(fixer_base.BaseFix):
# now stick the metaclass in the arglist
meta_txt = last_metaclass.children[0].children[0]
meta_txt.value = 'metaclass'
- orig_meta_prefix = meta_txt.get_prefix()
+ orig_meta_prefix = meta_txt.prefix
if arglist.children:
arglist.append_child(Leaf(token.COMMA, u','))
- meta_txt.set_prefix(u' ')
+ meta_txt.prefix = u' '
else:
- meta_txt.set_prefix(u'')
+ meta_txt.prefix = u''
# compact the expression "metaclass = Meta" -> "metaclass=Meta"
expr_stmt = last_metaclass.children[0]
assert expr_stmt.type == syms.expr_stmt
- expr_stmt.children[1].set_prefix(u'')
- expr_stmt.children[2].set_prefix(u'')
+ expr_stmt.children[1].prefix = u''
+ expr_stmt.children[2].prefix = u''
arglist.append_child(last_metaclass)
@@ -214,7 +214,7 @@ class FixMetaclass(fixer_base.BaseFix):
# one-liner that was just __metaclass_
suite.remove()
pass_leaf = Leaf(text_type, u'pass')
- pass_leaf.set_prefix(orig_meta_prefix)
+ pass_leaf.prefix = orig_meta_prefix
node.append_child(pass_leaf)
node.append_child(Leaf(token.NEWLINE, u'\n'))
diff --git a/Lib/lib2to3/fixes/fix_methodattrs.py b/Lib/lib2to3/fixes/fix_methodattrs.py
index 6ca2741..5e94a9c 100644
--- a/Lib/lib2to3/fixes/fix_methodattrs.py
+++ b/Lib/lib2to3/fixes/fix_methodattrs.py
@@ -20,4 +20,4 @@ class FixMethodattrs(fixer_base.BaseFix):
def transform(self, node, results):
attr = results["attr"][0]
new = unicode(MAP[attr.value])
- attr.replace(Name(new, prefix=attr.get_prefix()))
+ attr.replace(Name(new, prefix=attr.prefix))
diff --git a/Lib/lib2to3/fixes/fix_ne.py b/Lib/lib2to3/fixes/fix_ne.py
index 2535e32..23fe869 100644
--- a/Lib/lib2to3/fixes/fix_ne.py
+++ b/Lib/lib2to3/fixes/fix_ne.py
@@ -17,6 +17,5 @@ class FixNe(fixer_base.BaseFix):
return node.type == token.NOTEQUAL and node.value == u"<>"
def transform(self, node, results):
- new = pytree.Leaf(token.NOTEQUAL, u"!=")
- new.set_prefix(node.get_prefix())
+ new = pytree.Leaf(token.NOTEQUAL, u"!=", prefix=node.prefix)
return new
diff --git a/Lib/lib2to3/fixes/fix_next.py b/Lib/lib2to3/fixes/fix_next.py
index 8156814..c70f72b 100644
--- a/Lib/lib2to3/fixes/fix_next.py
+++ b/Lib/lib2to3/fixes/fix_next.py
@@ -48,17 +48,16 @@ class FixNext(fixer_base.BaseFix):
base = results.get("base")
attr = results.get("attr")
name = results.get("name")
- mod = results.get("mod")
if base:
if self.shadowed_next:
- attr.replace(Name(u"__next__", prefix=attr.get_prefix()))
+ attr.replace(Name(u"__next__", prefix=attr.prefix))
else:
base = [n.clone() for n in base]
- base[0].set_prefix(u"")
- node.replace(Call(Name(u"next", prefix=node.get_prefix()), base))
+ base[0].prefix = u""
+ node.replace(Call(Name(u"next", prefix=node.prefix), base))
elif name:
- n = Name(u"__next__", prefix=name.get_prefix())
+ n = Name(u"__next__", prefix=name.prefix)
name.replace(n)
elif attr:
# We don't do this transformation if we're assigning to "x.next".
diff --git a/Lib/lib2to3/fixes/fix_nonzero.py b/Lib/lib2to3/fixes/fix_nonzero.py
index 48632d7..17be377 100644
--- a/Lib/lib2to3/fixes/fix_nonzero.py
+++ b/Lib/lib2to3/fixes/fix_nonzero.py
@@ -16,5 +16,5 @@ class FixNonzero(fixer_base.BaseFix):
def transform(self, node, results):
name = results["name"]
- new = Name(u"__bool__", prefix=name.get_prefix())
+ new = Name(u"__bool__", prefix=name.prefix)
name.replace(new)
diff --git a/Lib/lib2to3/fixes/fix_numliterals.py b/Lib/lib2to3/fixes/fix_numliterals.py
index 871623b..a049aed 100644
--- a/Lib/lib2to3/fixes/fix_numliterals.py
+++ b/Lib/lib2to3/fixes/fix_numliterals.py
@@ -24,4 +24,4 @@ class FixNumliterals(fixer_base.BaseFix):
elif val.startswith(u'0') and val.isdigit() and len(set(val)) > 1:
val = u"0o" + val[1:]
- return Number(val, prefix=node.get_prefix())
+ return Number(val, prefix=node.prefix)
diff --git a/Lib/lib2to3/fixes/fix_paren.py b/Lib/lib2to3/fixes/fix_paren.py
index 8620206..eeb0d40 100644
--- a/Lib/lib2to3/fixes/fix_paren.py
+++ b/Lib/lib2to3/fixes/fix_paren.py
@@ -36,7 +36,7 @@ class FixParen(fixer_base.BaseFix):
target = results["target"]
lparen = LParen()
- lparen.set_prefix(target.get_prefix())
- target.set_prefix(u"") # Make it hug the parentheses
+ lparen.prefix = target.prefix
+ target.prefix = u"" # Make it hug the parentheses
target.insert_child(0, lparen)
target.append_child(RParen())
diff --git a/Lib/lib2to3/fixes/fix_print.py b/Lib/lib2to3/fixes/fix_print.py
index d3aa974..be29dce 100644
--- a/Lib/lib2to3/fixes/fix_print.py
+++ b/Lib/lib2to3/fixes/fix_print.py
@@ -45,7 +45,7 @@ class FixPrint(fixer_base.ConditionalFix):
if bare_print:
# Special-case print all by itself
bare_print.replace(Call(Name(u"print"), [],
- prefix=bare_print.get_prefix()))
+ prefix=bare_print.prefix))
return
assert node.children[0] == Name(u"print")
args = node.children[1:]
@@ -65,7 +65,7 @@ class FixPrint(fixer_base.ConditionalFix):
# Now synthesize a print(args, sep=..., end=..., file=...) node.
l_args = [arg.clone() for arg in args]
if l_args:
- l_args[0].set_prefix(u"")
+ l_args[0].prefix = u""
if sep is not None or end is not None or file is not None:
if sep is not None:
self.add_kwarg(l_args, u"sep", String(repr(sep)))
@@ -74,17 +74,17 @@ class FixPrint(fixer_base.ConditionalFix):
if file is not None:
self.add_kwarg(l_args, u"file", file)
n_stmt = Call(Name(u"print"), l_args)
- n_stmt.set_prefix(node.get_prefix())
+ n_stmt.prefix = node.prefix
return n_stmt
def add_kwarg(self, l_nodes, s_kwd, n_expr):
# XXX All this prefix-setting may lose comments (though rarely)
- n_expr.set_prefix(u"")
+ n_expr.prefix = u""
n_argument = pytree.Node(self.syms.argument,
(Name(s_kwd),
pytree.Leaf(token.EQUAL, u"="),
n_expr))
if l_nodes:
l_nodes.append(Comma())
- n_argument.set_prefix(u" ")
+ n_argument.prefix = u" "
l_nodes.append(n_argument)
diff --git a/Lib/lib2to3/fixes/fix_raise.py b/Lib/lib2to3/fixes/fix_raise.py
index e698912..24e123c 100644
--- a/Lib/lib2to3/fixes/fix_raise.py
+++ b/Lib/lib2to3/fixes/fix_raise.py
@@ -52,31 +52,31 @@ class FixRaise(fixer_base.BaseFix):
# 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(" ")
+ exc.prefix = " "
if "val" not in results:
# One-argument raise
new = pytree.Node(syms.raise_stmt, [Name(u"raise"), exc])
- new.set_prefix(node.get_prefix())
+ new.prefix = node.prefix
return new
val = results["val"].clone()
if is_tuple(val):
args = [c.clone() for c in val.children[1:-1]]
else:
- val.set_prefix(u"")
+ val.prefix = u""
args = [val]
if "tb" in results:
tb = results["tb"].clone()
- tb.set_prefix(u"")
+ tb.prefix = u""
e = Call(exc, args)
with_tb = Attr(e, Name(u'with_traceback')) + [ArgList([tb])]
new = pytree.Node(syms.simple_stmt, [Name(u"raise")] + with_tb)
- new.set_prefix(node.get_prefix())
+ new.prefix = node.prefix
return new
else:
return pytree.Node(syms.raise_stmt,
[Name(u"raise"), Call(exc, args)],
- prefix=node.get_prefix())
+ prefix=node.prefix)
diff --git a/Lib/lib2to3/fixes/fix_raw_input.py b/Lib/lib2to3/fixes/fix_raw_input.py
index b95ac87..ba045d6 100644
--- a/Lib/lib2to3/fixes/fix_raw_input.py
+++ b/Lib/lib2to3/fixes/fix_raw_input.py
@@ -13,4 +13,4 @@ class FixRawInput(fixer_base.BaseFix):
def transform(self, node, results):
name = results["name"]
- name.replace(Name(u"input", prefix=name.get_prefix()))
+ name.replace(Name(u"input", prefix=name.prefix))
diff --git a/Lib/lib2to3/fixes/fix_renames.py b/Lib/lib2to3/fixes/fix_renames.py
index 0f4bcaf..ae398c7 100644
--- a/Lib/lib2to3/fixes/fix_renames.py
+++ b/Lib/lib2to3/fixes/fix_renames.py
@@ -66,4 +66,4 @@ class FixRenames(fixer_base.BaseFix):
if mod_name and attr_name:
new_attr = unicode(LOOKUP[(mod_name.value, attr_name.value)])
- attr_name.replace(Name(new_attr, prefix=attr_name.get_prefix()))
+ attr_name.replace(Name(new_attr, prefix=attr_name.prefix))
diff --git a/Lib/lib2to3/fixes/fix_repr.py b/Lib/lib2to3/fixes/fix_repr.py
index 07974ff..4b37e73 100644
--- a/Lib/lib2to3/fixes/fix_repr.py
+++ b/Lib/lib2to3/fixes/fix_repr.py
@@ -19,4 +19,4 @@ class FixRepr(fixer_base.BaseFix):
if expr.type == self.syms.testlist1:
expr = parenthesize(expr)
- return Call(Name(u"repr"), [expr], prefix=node.get_prefix())
+ return Call(Name(u"repr"), [expr], prefix=node.prefix)
diff --git a/Lib/lib2to3/fixes/fix_set_literal.py b/Lib/lib2to3/fixes/fix_set_literal.py
index 97b318d..cfc522c 100644
--- a/Lib/lib2to3/fixes/fix_set_literal.py
+++ b/Lib/lib2to3/fixes/fix_set_literal.py
@@ -38,15 +38,15 @@ class FixSetLiteral(fixer_base.BaseFix):
literal.extend(n.clone() for n in items.children)
literal.append(pytree.Leaf(token.RBRACE, u"}"))
# Set the prefix of the right brace to that of the ')' or ']'
- literal[-1].set_prefix(items.next_sibling.get_prefix())
+ literal[-1].prefix = items.next_sibling.prefix
maker = pytree.Node(syms.dictsetmaker, literal)
- maker.set_prefix(node.get_prefix())
+ maker.prefix = node.prefix
# If the original was a one tuple, we need to remove the extra comma.
if len(maker.children) == 4:
n = maker.children[2]
n.remove()
- maker.children[-1].set_prefix(n.get_prefix())
+ maker.children[-1].prefix = n.prefix
# Finally, replace the set call with our shiny new literal.
return maker
diff --git a/Lib/lib2to3/fixes/fix_standarderror.py b/Lib/lib2to3/fixes/fix_standarderror.py
index 44cbb57..a5789ba 100644
--- a/Lib/lib2to3/fixes/fix_standarderror.py
+++ b/Lib/lib2to3/fixes/fix_standarderror.py
@@ -15,4 +15,4 @@ class FixStandarderror(fixer_base.BaseFix):
"""
def transform(self, node, results):
- return Name(u"Exception", prefix=node.get_prefix())
+ return Name(u"Exception", prefix=node.prefix)
diff --git a/Lib/lib2to3/fixes/fix_sys_exc.py b/Lib/lib2to3/fixes/fix_sys_exc.py
index 936183f..608de18 100644
--- a/Lib/lib2to3/fixes/fix_sys_exc.py
+++ b/Lib/lib2to3/fixes/fix_sys_exc.py
@@ -22,8 +22,8 @@ class FixSysExc(fixer_base.BaseFix):
sys_attr = results["attribute"][0]
index = Number(self.exc_info.index(sys_attr.value))
- call = Call(Name(u"exc_info"), prefix=sys_attr.get_prefix())
+ call = Call(Name(u"exc_info"), prefix=sys_attr.prefix)
attr = Attr(Name(u"sys"), call)
- attr[1].children[0].set_prefix(results["dot"].get_prefix())
+ attr[1].children[0].prefix = results["dot"].prefix
attr.append(Subscript(index))
- return Node(syms.power, attr, prefix=node.get_prefix())
+ return Node(syms.power, attr, prefix=node.prefix)
diff --git a/Lib/lib2to3/fixes/fix_throw.py b/Lib/lib2to3/fixes/fix_throw.py
index 90ffc64..63271cf 100644
--- a/Lib/lib2to3/fixes/fix_throw.py
+++ b/Lib/lib2to3/fixes/fix_throw.py
@@ -40,14 +40,14 @@ class FixThrow(fixer_base.BaseFix):
if is_tuple(val):
args = [c.clone() for c in val.children[1:-1]]
else:
- val.set_prefix(u"")
+ val.prefix = u""
args = [val]
throw_args = results["args"]
if "tb" in results:
tb = results["tb"].clone()
- tb.set_prefix(u"")
+ tb.prefix = u""
e = Call(exc, args)
with_tb = Attr(e, Name(u'with_traceback')) + [ArgList([tb])]
diff --git a/Lib/lib2to3/fixes/fix_tuple_params.py b/Lib/lib2to3/fixes/fix_tuple_params.py
index 6628518..b887403 100644
--- a/Lib/lib2to3/fixes/fix_tuple_params.py
+++ b/Lib/lib2to3/fixes/fix_tuple_params.py
@@ -63,10 +63,10 @@ class FixTupleParams(fixer_base.BaseFix):
def handle_tuple(tuple_arg, add_prefix=False):
n = Name(self.new_name())
arg = tuple_arg.clone()
- arg.set_prefix(u"")
+ arg.prefix = u""
stmt = Assign(arg, n.clone())
if add_prefix:
- n.set_prefix(u" ")
+ n.prefix = u" "
tuple_arg.replace(n)
new_lines.append(pytree.Node(syms.simple_stmt,
[stmt, end.clone()]))
@@ -91,14 +91,14 @@ class FixTupleParams(fixer_base.BaseFix):
# TODO(cwinter) suite-cleanup
after = start
if start == 0:
- new_lines[0].set_prefix(u" ")
+ new_lines[0].prefix = u" "
elif is_docstring(suite[0].children[start]):
- new_lines[0].set_prefix(indent)
+ new_lines[0].prefix = indent
after = start + 1
suite[0].children[after:after] = new_lines
for i in range(after+1, after+len(new_lines)+1):
- suite[0].children[i].set_prefix(indent)
+ suite[0].children[i].prefix = indent
suite[0].changed()
def transform_lambda(self, node, results):
@@ -109,7 +109,7 @@ class FixTupleParams(fixer_base.BaseFix):
# Replace lambda ((((x)))): x with lambda x: x
if inner.type == token.NAME:
inner = inner.clone()
- inner.set_prefix(u" ")
+ inner.prefix = u" "
args.replace(inner)
return
@@ -124,7 +124,7 @@ class FixTupleParams(fixer_base.BaseFix):
subscripts = [c.clone() for c in to_index[n.value]]
new = pytree.Node(syms.power,
[new_param.clone()] + subscripts)
- new.set_prefix(n.get_prefix())
+ new.prefix = n.prefix
n.replace(new)
diff --git a/Lib/lib2to3/fixes/fix_types.py b/Lib/lib2to3/fixes/fix_types.py
index 9327248..2fbbab8 100644
--- a/Lib/lib2to3/fixes/fix_types.py
+++ b/Lib/lib2to3/fixes/fix_types.py
@@ -58,5 +58,5 @@ class FixTypes(fixer_base.BaseFix):
def transform(self, node, results):
new_value = unicode(_TYPE_MAPPING.get(results["name"].value))
if new_value:
- return Name(new_value, prefix=node.get_prefix())
+ return Name(new_value, prefix=node.prefix)
return None
diff --git a/Lib/lib2to3/fixes/fix_unicode.py b/Lib/lib2to3/fixes/fix_unicode.py
index 580e82d..cd3b89c 100644
--- a/Lib/lib2to3/fixes/fix_unicode.py
+++ b/Lib/lib2to3/fixes/fix_unicode.py
@@ -6,23 +6,20 @@ import re
from ..pgen2 import token
from .. import fixer_base
+_mapping = {u"unichr" : u"chr", u"unicode" : u"str"}
+_literal_re = re.compile(ur"[uU][rR]?[\'\"]")
+
class FixUnicode(fixer_base.BaseFix):
- PATTERN = "STRING | NAME<'unicode' | 'unichr'>"
+ PATTERN = "STRING | 'unicode' | 'unichr'"
def transform(self, node, results):
if node.type == token.NAME:
- if node.value == u"unicode":
- new = node.clone()
- new.value = u"str"
- return new
- if node.value == u"unichr":
- new = node.clone()
- new.value = u"chr"
- return new
- # XXX Warn when __unicode__ found?
+ new = node.clone()
+ new.value = _mapping[node.value]
+ return new
elif node.type == token.STRING:
- if re.match(ur"[uU][rR]?[\'\"]", node.value):
+ if _literal_re.match(node.value):
new = node.clone()
new.value = new.value[1:]
return new
diff --git a/Lib/lib2to3/fixes/fix_urllib.py b/Lib/lib2to3/fixes/fix_urllib.py
index f262537..a89266e 100644
--- a/Lib/lib2to3/fixes/fix_urllib.py
+++ b/Lib/lib2to3/fixes/fix_urllib.py
@@ -78,7 +78,7 @@ class FixUrllib(FixImports):
replacements.
"""
import_mod = results.get('module')
- pref = import_mod.get_prefix()
+ pref = import_mod.prefix
names = []
@@ -94,7 +94,7 @@ class FixUrllib(FixImports):
module.
"""
mod_member = results.get('mod_member')
- pref = mod_member.get_prefix()
+ pref = mod_member.prefix
member = results.get('member')
# Simple case with only a single member being imported
@@ -162,7 +162,7 @@ class FixUrllib(FixImports):
break
if new_name:
module_dot.replace(Name(new_name,
- prefix=module_dot.get_prefix()))
+ prefix=module_dot.prefix))
else:
self.cannot_convert(node, 'This is an invalid module element')
diff --git a/Lib/lib2to3/fixes/fix_ws_comma.py b/Lib/lib2to3/fixes/fix_ws_comma.py
index b5bfd8c..37ff624 100644
--- a/Lib/lib2to3/fixes/fix_ws_comma.py
+++ b/Lib/lib2to3/fixes/fix_ws_comma.py
@@ -26,14 +26,14 @@ class FixWsComma(fixer_base.BaseFix):
comma = False
for child in new.children:
if child in self.SEPS:
- prefix = child.get_prefix()
+ prefix = child.prefix
if prefix.isspace() and u"\n" not in prefix:
- child.set_prefix(u"")
+ child.prefix = u""
comma = True
else:
if comma:
- prefix = child.get_prefix()
+ prefix = child.prefix
if not prefix:
- child.set_prefix(u" ")
+ child.prefix = u" "
comma = False
return new
diff --git a/Lib/lib2to3/fixes/fix_xrange.py b/Lib/lib2to3/fixes/fix_xrange.py
index c472a03..ad910a7 100644
--- a/Lib/lib2to3/fixes/fix_xrange.py
+++ b/Lib/lib2to3/fixes/fix_xrange.py
@@ -28,14 +28,14 @@ class FixXrange(fixer_base.BaseFix):
def transform_xrange(self, node, results):
name = results["name"]
- name.replace(Name(u"range", prefix=name.get_prefix()))
+ name.replace(Name(u"range", prefix=name.prefix))
def transform_range(self, node, results):
if not self.in_special_context(node):
range_call = Call(Name(u"range"), [results["args"].clone()])
# Encase the range call in list().
list_call = Call(Name(u"list"), [range_call],
- prefix=node.get_prefix())
+ prefix=node.prefix)
# Put things that were after the range() call after the list call.
for n in results["rest"]:
list_call.append_child(n)
diff --git a/Lib/lib2to3/fixes/fix_xreadlines.py b/Lib/lib2to3/fixes/fix_xreadlines.py
index 4880751..ee4b356 100644
--- a/Lib/lib2to3/fixes/fix_xreadlines.py
+++ b/Lib/lib2to3/fixes/fix_xreadlines.py
@@ -19,6 +19,6 @@ class FixXreadlines(fixer_base.BaseFix):
no_call = results.get("no_call")
if no_call:
- no_call.replace(Name(u"__iter__", prefix=no_call.get_prefix()))
+ no_call.replace(Name(u"__iter__", prefix=no_call.prefix))
else:
node.replace([x.clone() for x in results["call"]])
diff --git a/Lib/lib2to3/fixes/fix_zip.py b/Lib/lib2to3/fixes/fix_zip.py
index e990842..6736a7e 100644
--- a/Lib/lib2to3/fixes/fix_zip.py
+++ b/Lib/lib2to3/fixes/fix_zip.py
@@ -28,7 +28,7 @@ class FixZip(fixer_base.ConditionalFix):
return None
new = node.clone()
- new.set_prefix(u"")
+ new.prefix = u""
new = Call(Name(u"list"), [new])
- new.set_prefix(node.get_prefix())
+ new.prefix = node.prefix
return new