diff options
Diffstat (limited to 'Lib/lib2to3/fixes')
45 files changed, 139 insertions, 139 deletions
diff --git a/Lib/lib2to3/fixes/fix_apply.py b/Lib/lib2to3/fixes/fix_apply.py index 5af13b7..953b9b1 100644 --- a/Lib/lib2to3/fixes/fix_apply.py +++ b/Lib/lib2to3/fixes/fix_apply.py @@ -46,12 +46,12 @@ class FixApply(fixer_base.BaseFix): if kwds is not None: kwds = kwds.clone() kwds.set_prefix("") - l_newargs = [pytree.Leaf(token.STAR, "*"), args] + l_newargs = [pytree.Leaf(token.STAR, u"*"), args] if kwds is not None: l_newargs.extend([Comma(), - pytree.Leaf(token.DOUBLESTAR, "**"), + pytree.Leaf(token.DOUBLESTAR, u"**"), kwds]) - l_newargs[-2].set_prefix(" ") # that's the ** token + l_newargs[-2].set_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 5d84cc7..138e732 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("str", prefix=node.get_prefix()) + return Name(u"str", prefix=node.get_prefix()) diff --git a/Lib/lib2to3/fixes/fix_buffer.py b/Lib/lib2to3/fixes/fix_buffer.py index 2f6822b..34cc168 100644 --- a/Lib/lib2to3/fixes/fix_buffer.py +++ b/Lib/lib2to3/fixes/fix_buffer.py @@ -18,4 +18,4 @@ class FixBuffer(fixer_base.BaseFix): def transform(self, node, results): name = results["name"] - name.replace(Name("memoryview", prefix=name.get_prefix())) + name.replace(Name(u"memoryview", prefix=name.get_prefix())) diff --git a/Lib/lib2to3/fixes/fix_callable.py b/Lib/lib2to3/fixes/fix_callable.py index de93792..4de3f66 100644 --- a/Lib/lib2to3/fixes/fix_callable.py +++ b/Lib/lib2to3/fixes/fix_callable.py @@ -27,5 +27,5 @@ class FixCallable(fixer_base.BaseFix): def transform(self, node, results): 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()) diff --git a/Lib/lib2to3/fixes/fix_dict.py b/Lib/lib2to3/fixes/fix_dict.py index dec94c5..b0b9de0 100644 --- a/Lib/lib2to3/fixes/fix_dict.py +++ b/Lib/lib2to3/fixes/fix_dict.py @@ -51,7 +51,7 @@ class FixDict(fixer_base.BaseFix): tail = results["tail"] syms = self.syms method_name = method.value - isiter = method_name.startswith("iter") + isiter = method_name.startswith(u"iter") if isiter: method_name = method_name[4:] assert method_name in ("keys", "items", "values"), repr(method) @@ -65,8 +65,8 @@ class FixDict(fixer_base.BaseFix): results["parens"].clone()] new = pytree.Node(syms.power, args) if not special: - new.set_prefix("") - new = Call(Name(isiter and "iter" or "list"), [new]) + new.set_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()) diff --git a/Lib/lib2to3/fixes/fix_except.py b/Lib/lib2to3/fixes/fix_except.py index 5554c02..edac97e 100644 --- a/Lib/lib2to3/fixes/fix_except.py +++ b/Lib/lib2to3/fixes/fix_except.py @@ -30,7 +30,7 @@ from ..fixer_util import Assign, Attr, Name, is_tuple, is_list, syms def find_excepts(nodes): for i, n in enumerate(nodes): if n.type == syms.except_clause: - if n.children[0].value == 'except': + if n.children[0].value == u'except': yield (n, nodes[i+2]) class FixExcept(fixer_base.BaseFix): @@ -52,13 +52,13 @@ class FixExcept(fixer_base.BaseFix): for except_clause, e_suite in find_excepts(try_cleanup): if len(except_clause.children) == 4: (E, comma, N) = except_clause.children[1:4] - comma.replace(Name("as", prefix=" ")) + comma.replace(Name(u"as", prefix=u" ")) if N.type != token.NAME: # Generate a new N for the except clause - new_N = Name(self.new_name(), prefix=" ") + new_N = Name(self.new_name(), prefix=u" ") target = N.clone() - target.set_prefix("") + target.set_prefix(u"") N.replace(new_N) new_N = new_N.clone() @@ -74,7 +74,7 @@ class FixExcept(fixer_base.BaseFix): # The assignment is different if old_N is a tuple or list # In that case, the assignment is old_N = new_N.args if is_tuple(N) or is_list(N): - assign = Assign(target, Attr(new_N, Name('args'))) + assign = Assign(target, Attr(new_N, Name(u'args'))) else: assign = Assign(target, new_N) @@ -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() == "": + elif N.get_prefix() == u"": # No space after a comma is legal; no space after "as", # not so much. - N.set_prefix(" ") + N.set_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 9b47aec..adc8eb0 100644 --- a/Lib/lib2to3/fixes/fix_exec.py +++ b/Lib/lib2to3/fixes/fix_exec.py @@ -36,4 +36,4 @@ class FixExec(fixer_base.BaseFix): if c is not None: args.extend([Comma(), c.clone()]) - return Call(Name("exec"), args, prefix=node.get_prefix()) + return Call(Name(u"exec"), args, prefix=node.get_prefix()) diff --git a/Lib/lib2to3/fixes/fix_execfile.py b/Lib/lib2to3/fixes/fix_execfile.py index f7a7a70..d8997cf 100644 --- a/Lib/lib2to3/fixes/fix_execfile.py +++ b/Lib/lib2to3/fixes/fix_execfile.py @@ -31,21 +31,21 @@ class FixExecfile(fixer_base.BaseFix): execfile_paren = node.children[-1].children[-1].clone() # Construct open().read(). open_args = ArgList([filename.clone()], rparen=execfile_paren) - open_call = Node(syms.power, [Name("open"), open_args]) - read = [Node(syms.trailer, [Dot(), Name('read')]), + open_call = Node(syms.power, [Name(u"open"), open_args]) + read = [Node(syms.trailer, [Dot(), Name(u'read')]), Node(syms.trailer, [LParen(), RParen()])] open_expr = [open_call] + read # 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(" ") - exec_str = String("'exec'", " ") + filename_arg.set_prefix(u" ") + exec_str = String(u"'exec'", u" ") compile_args = open_expr + [Comma(), filename_arg, Comma(), exec_str] - compile_call = Call(Name("compile"), compile_args, "") + compile_call = Call(Name(u"compile"), compile_args, u"") # Finally, replace the execfile call with an exec call. args = [compile_call] if globals is not None: args.extend([Comma(), globals.clone()]) if locals is not None: args.extend([Comma(), locals.clone()]) - return Call(Name("exec"), args, prefix=node.get_prefix()) + return Call(Name(u"exec"), args, prefix=node.get_prefix()) diff --git a/Lib/lib2to3/fixes/fix_filter.py b/Lib/lib2to3/fixes/fix_filter.py index 51fd02a..946be3e 100644 --- a/Lib/lib2to3/fixes/fix_filter.py +++ b/Lib/lib2to3/fixes/fix_filter.py @@ -60,16 +60,16 @@ class FixFilter(fixer_base.ConditionalFix): results.get("xp").clone()) elif "none" in results: - new = ListComp(Name("_f"), - Name("_f"), + new = ListComp(Name(u"_f"), + Name(u"_f"), results["seq"].clone(), - Name("_f")) + Name(u"_f")) else: if in_special_context(node): return None new = node.clone() - new.set_prefix("") - new = Call(Name("list"), [new]) + new.set_prefix(u"") + new = Call(Name(u"list"), [new]) new.set_prefix(node.get_prefix()) return new diff --git a/Lib/lib2to3/fixes/fix_funcattrs.py b/Lib/lib2to3/fixes/fix_funcattrs.py index 4234993..680cb35 100644 --- a/Lib/lib2to3/fixes/fix_funcattrs.py +++ b/Lib/lib2to3/fixes/fix_funcattrs.py @@ -15,5 +15,5 @@ class FixFuncattrs(fixer_base.BaseFix): def transform(self, node, results): attr = results["attr"][0] - attr.replace(Name(("__%s__" % attr.value[5:]), + attr.replace(Name((u"__%s__" % attr.value[5:]), prefix=attr.get_prefix())) diff --git a/Lib/lib2to3/fixes/fix_getcwdu.py b/Lib/lib2to3/fixes/fix_getcwdu.py index 1175e56..1e1e2fe 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("getcwd", prefix=name.get_prefix())) + name.replace(Name(u"getcwd", prefix=name.get_prefix())) diff --git a/Lib/lib2to3/fixes/fix_has_key.py b/Lib/lib2to3/fixes/fix_has_key.py index 482f27d..ec7210a 100644 --- a/Lib/lib2to3/fixes/fix_has_key.py +++ b/Lib/lib2to3/fixes/fix_has_key.py @@ -91,10 +91,10 @@ class FixHasKey(fixer_base.BaseFix): before = before[0] else: before = pytree.Node(syms.power, before) - before.set_prefix(" ") - n_op = Name("in", prefix=" ") + before.set_prefix(u" ") + n_op = Name(u"in", prefix=u" ") if negation: - n_not = Name("not", prefix=" ") + n_not = Name(u"not", prefix=u" ") n_op = pytree.Node(syms.comp_op, (n_not, n_op)) new = pytree.Node(syms.comparison, (arg, n_op, before)) if after: diff --git a/Lib/lib2to3/fixes/fix_idioms.py b/Lib/lib2to3/fixes/fix_idioms.py index 8bc6397..6977c7f 100644 --- a/Lib/lib2to3/fixes/fix_idioms.py +++ b/Lib/lib2to3/fixes/fix_idioms.py @@ -105,14 +105,14 @@ class FixIdioms(fixer_base.BaseFix): T.set_prefix(" ") test = Call(Name("isinstance"), [x, Comma(), T]) if "n" in results: - test.set_prefix(" ") - test = Node(syms.not_test, [Name("not"), test]) + test.set_prefix(u" ") + test = Node(syms.not_test, [Name(u"not"), test]) test.set_prefix(node.get_prefix()) return test def transform_while(self, node, results): one = results["while"] - one.replace(Name("True", prefix=one.get_prefix())) + one.replace(Name(u"True", prefix=one.get_prefix())) def transform_sort(self, node, results): sort_stmt = results["sort"] @@ -121,11 +121,11 @@ class FixIdioms(fixer_base.BaseFix): simple_expr = results.get("expr") if list_call: - list_call.replace(Name("sorted", prefix=list_call.get_prefix())) + list_call.replace(Name(u"sorted", prefix=list_call.get_prefix())) elif simple_expr: new = simple_expr.clone() - new.set_prefix("") - simple_expr.replace(Call(Name("sorted"), [new], + new.set_prefix(u"") + simple_expr.replace(Call(Name(u"sorted"), [new], prefix=simple_expr.get_prefix())) else: raise RuntimeError("should not have reached here") diff --git a/Lib/lib2to3/fixes/fix_import.py b/Lib/lib2to3/fixes/fix_import.py index 4c75133..50ffb41 100644 --- a/Lib/lib2to3/fixes/fix_import.py +++ b/Lib/lib2to3/fixes/fix_import.py @@ -54,7 +54,7 @@ class FixImport(fixer_base.BaseFix): while not hasattr(imp, 'value'): imp = imp.children[0] if self.probably_a_local_import(imp.value): - imp.value = "." + imp.value + imp.value = u"." + imp.value imp.changed() return node else: diff --git a/Lib/lib2to3/fixes/fix_imports.py b/Lib/lib2to3/fixes/fix_imports.py index 46ba4a2..3236a08 100644 --- a/Lib/lib2to3/fixes/fix_imports.py +++ b/Lib/lib2to3/fixes/fix_imports.py @@ -123,7 +123,7 @@ class FixImports(fixer_base.BaseFix): import_mod = results.get("module_name") if import_mod: mod_name = import_mod.value - new_name = self.mapping[mod_name] + new_name = unicode(self.mapping[mod_name]) import_mod.replace(Name(new_name, prefix=import_mod.get_prefix())) if "name_import" in results: # If it's not a "from x import x, y" or "import x as y" import, diff --git a/Lib/lib2to3/fixes/fix_input.py b/Lib/lib2to3/fixes/fix_input.py index e0264cf..3e330f6 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("") - return Call(Name("eval"), [new], prefix=node.get_prefix()) + new.set_prefix(u"") + return Call(Name(u"eval"), [new], prefix=node.get_prefix()) diff --git a/Lib/lib2to3/fixes/fix_intern.py b/Lib/lib2to3/fixes/fix_intern.py index 66c616e..46e5239 100644 --- a/Lib/lib2to3/fixes/fix_intern.py +++ b/Lib/lib2to3/fixes/fix_intern.py @@ -34,11 +34,11 @@ class FixIntern(fixer_base.BaseFix): if after: after = [n.clone() for n in after] new = pytree.Node(syms.power, - Attr(Name("sys"), Name("intern")) + + Attr(Name(u"sys"), Name(u"intern")) + [pytree.Node(syms.trailer, [results["lpar"].clone(), newarglist, results["rpar"].clone()])] + after) new.set_prefix(node.get_prefix()) - touch_import(None, 'sys', node) + touch_import(None, u'sys', node) return new diff --git a/Lib/lib2to3/fixes/fix_itertools.py b/Lib/lib2to3/fixes/fix_itertools.py index 86d6b46..d781cf3 100644 --- a/Lib/lib2to3/fixes/fix_itertools.py +++ b/Lib/lib2to3/fixes/fix_itertools.py @@ -27,7 +27,7 @@ class FixItertools(fixer_base.BaseFix): def transform(self, node, results): prefix = None func = results['func'][0] - if 'it' in results and func.value != 'ifilterfalse': + if 'it' in results and func.value != u'ifilterfalse': dot, it = (results['dot'], results['it']) # Remove the 'itertools' prefix = it.get_prefix() diff --git a/Lib/lib2to3/fixes/fix_itertools_imports.py b/Lib/lib2to3/fixes/fix_itertools_imports.py index 8a57f6d..4df2301 100644 --- a/Lib/lib2to3/fixes/fix_itertools_imports.py +++ b/Lib/lib2to3/fixes/fix_itertools_imports.py @@ -24,12 +24,12 @@ class FixItertoolsImports(fixer_base.BaseFix): assert child.type == syms.import_as_name name_node = child.children[0] member_name = name_node.value - if member_name in ('imap', 'izip', 'ifilter'): + if member_name in (u'imap', u'izip', u'ifilter'): child.value = None child.remove() - elif member_name == 'ifilterfalse': + elif member_name == u'ifilterfalse': node.changed() - name_node.value = 'filterfalse' + name_node.value = u'filterfalse' # Make sure the import statement is still sane children = imports.children[:] or [imports] diff --git a/Lib/lib2to3/fixes/fix_long.py b/Lib/lib2to3/fixes/fix_long.py index 873ecf1..3232902 100644 --- a/Lib/lib2to3/fixes/fix_long.py +++ b/Lib/lib2to3/fixes/fix_long.py @@ -13,7 +13,7 @@ class FixLong(fixer_base.BaseFix): PATTERN = "'long'" - static_int = Name("int") + static_int = Name(u"int") def transform(self, node, results): if is_probably_builtin(node): diff --git a/Lib/lib2to3/fixes/fix_map.py b/Lib/lib2to3/fixes/fix_map.py index 29578e2..c57154d 100644 --- a/Lib/lib2to3/fixes/fix_map.py +++ b/Lib/lib2to3/fixes/fix_map.py @@ -63,8 +63,8 @@ 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("") - new = Call(Name("list"), [new]) + new.set_prefix(u"") + new = Call(Name(u"list"), [new]) elif "map_lambda" in results: new = ListComp(results.get("xp").clone(), results.get("fp").clone(), @@ -76,7 +76,7 @@ class FixMap(fixer_base.ConditionalFix): if in_special_context(node): return None new = node.clone() - new.set_prefix("") - new = Call(Name("list"), [new]) + new.set_prefix(u"") + new = Call(Name(u"list"), [new]) new.set_prefix(node.get_prefix()) return new diff --git a/Lib/lib2to3/fixes/fix_metaclass.py b/Lib/lib2to3/fixes/fix_metaclass.py index b508f5f..3b1b3ea 100644 --- a/Lib/lib2to3/fixes/fix_metaclass.py +++ b/Lib/lib2to3/fixes/fix_metaclass.py @@ -113,7 +113,7 @@ def find_metas(cls_node): # Check if the expr_node is a simple assignment. left_node = expr_node.children[0] if isinstance(left_node, Leaf) and \ - left_node.value == '__metaclass__': + left_node.value == u'__metaclass__': # We found a assignment to __metaclass__. fixup_simple_stmt(node, i, simple_node) remove_trailing_newline(simple_node) @@ -182,9 +182,9 @@ class FixMetaclass(fixer_base.BaseFix): # Node(classdef, ['class', 'name', ':', suite]) # 0 1 2 3 arglist = Node(syms.arglist, []) - node.insert_child(2, Leaf(token.RPAR, ')')) + node.insert_child(2, Leaf(token.RPAR, u')')) node.insert_child(2, arglist) - node.insert_child(2, Leaf(token.LPAR, '(')) + node.insert_child(2, Leaf(token.LPAR, u'(')) else: raise ValueError("Unexpected class definition") @@ -194,16 +194,16 @@ class FixMetaclass(fixer_base.BaseFix): orig_meta_prefix = meta_txt.get_prefix() if arglist.children: - arglist.append_child(Leaf(token.COMMA, ',')) - meta_txt.set_prefix(' ') + arglist.append_child(Leaf(token.COMMA, u',')) + meta_txt.set_prefix(u' ') else: - meta_txt.set_prefix('') + meta_txt.set_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('') - expr_stmt.children[2].set_prefix('') + expr_stmt.children[1].set_prefix(u'') + expr_stmt.children[2].set_prefix(u'') arglist.append_child(last_metaclass) @@ -213,15 +213,15 @@ class FixMetaclass(fixer_base.BaseFix): if not suite.children: # one-liner that was just __metaclass_ suite.remove() - pass_leaf = Leaf(text_type, 'pass') + pass_leaf = Leaf(text_type, u'pass') pass_leaf.set_prefix(orig_meta_prefix) node.append_child(pass_leaf) - node.append_child(Leaf(token.NEWLINE, '\n')) + node.append_child(Leaf(token.NEWLINE, u'\n')) elif len(suite.children) > 1 and \ (suite.children[-2].type == token.INDENT and suite.children[-1].type == token.DEDENT): # there was only one line in the class body and it was __metaclass__ - pass_leaf = Leaf(text_type, 'pass') + pass_leaf = Leaf(text_type, u'pass') suite.insert_child(-1, pass_leaf) - suite.insert_child(-1, Leaf(token.NEWLINE, '\n')) + suite.insert_child(-1, Leaf(token.NEWLINE, u'\n')) diff --git a/Lib/lib2to3/fixes/fix_methodattrs.py b/Lib/lib2to3/fixes/fix_methodattrs.py index ae4096c..6ca2741 100644 --- a/Lib/lib2to3/fixes/fix_methodattrs.py +++ b/Lib/lib2to3/fixes/fix_methodattrs.py @@ -19,5 +19,5 @@ class FixMethodattrs(fixer_base.BaseFix): def transform(self, node, results): attr = results["attr"][0] - new = MAP[attr.value] + new = unicode(MAP[attr.value]) attr.replace(Name(new, prefix=attr.get_prefix())) diff --git a/Lib/lib2to3/fixes/fix_ne.py b/Lib/lib2to3/fixes/fix_ne.py index 382f43d..2535e32 100644 --- a/Lib/lib2to3/fixes/fix_ne.py +++ b/Lib/lib2to3/fixes/fix_ne.py @@ -14,9 +14,9 @@ class FixNe(fixer_base.BaseFix): def match(self, node): # Override - return node.type == token.NOTEQUAL and node.value == "<>" + return node.type == token.NOTEQUAL and node.value == u"<>" def transform(self, node, results): - new = pytree.Leaf(token.NOTEQUAL, "!=") + new = pytree.Leaf(token.NOTEQUAL, u"!=") new.set_prefix(node.get_prefix()) return new diff --git a/Lib/lib2to3/fixes/fix_next.py b/Lib/lib2to3/fixes/fix_next.py index 492b515..8156814 100644 --- a/Lib/lib2to3/fixes/fix_next.py +++ b/Lib/lib2to3/fixes/fix_next.py @@ -35,7 +35,7 @@ class FixNext(fixer_base.BaseFix): def start_tree(self, tree, filename): super(FixNext, self).start_tree(tree, filename) - n = find_binding('next', tree) + n = find_binding(u'next', tree) if n: self.warning(n, bind_warning) self.shadowed_next = True @@ -52,13 +52,13 @@ class FixNext(fixer_base.BaseFix): if base: if self.shadowed_next: - attr.replace(Name("__next__", prefix=attr.get_prefix())) + attr.replace(Name(u"__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)) + base[0].set_prefix(u"") + node.replace(Call(Name(u"next", prefix=node.get_prefix()), base)) elif name: - n = Name("__next__", prefix=name.get_prefix()) + n = Name(u"__next__", prefix=name.get_prefix()) name.replace(n) elif attr: # We don't do this transformation if we're assigning to "x.next". @@ -66,10 +66,10 @@ class FixNext(fixer_base.BaseFix): # so it's being done here. if is_assign_target(node): head = results["head"] - if "".join([str(n) for n in head]).strip() == '__builtin__': + if "".join([str(n) for n in head]).strip() == u'__builtin__': self.warning(node, bind_warning) return - attr.replace(Name("__next__")) + attr.replace(Name(u"__next__")) elif "global" in results: self.warning(node, bind_warning) self.shadowed_next = True diff --git a/Lib/lib2to3/fixes/fix_nonzero.py b/Lib/lib2to3/fixes/fix_nonzero.py index abb1f4e..48632d7 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("__bool__", prefix=name.get_prefix()) + new = Name(u"__bool__", prefix=name.get_prefix()) name.replace(new) diff --git a/Lib/lib2to3/fixes/fix_numliterals.py b/Lib/lib2to3/fixes/fix_numliterals.py index d821e39..871623b 100644 --- a/Lib/lib2to3/fixes/fix_numliterals.py +++ b/Lib/lib2to3/fixes/fix_numliterals.py @@ -15,13 +15,13 @@ class FixNumliterals(fixer_base.BaseFix): def match(self, node): # Override return (node.type == token.NUMBER and - (node.value.startswith("0") or node.value[-1] in "Ll")) + (node.value.startswith(u"0") or node.value[-1] in u"Ll")) def transform(self, node, results): val = node.value - if val[-1] in 'Ll': + if val[-1] in u'Ll': val = val[:-1] - elif val.startswith('0') and val.isdigit() and len(set(val)) > 1: - val = "0o" + val[1:] + 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()) diff --git a/Lib/lib2to3/fixes/fix_paren.py b/Lib/lib2to3/fixes/fix_paren.py index 0b72bb1..8620206 100644 --- a/Lib/lib2to3/fixes/fix_paren.py +++ b/Lib/lib2to3/fixes/fix_paren.py @@ -37,6 +37,6 @@ class FixParen(fixer_base.BaseFix): lparen = LParen() lparen.set_prefix(target.get_prefix()) - target.set_prefix("") # Make it hug the parentheses + target.set_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 134a972..d3aa974 100644 --- a/Lib/lib2to3/fixes/fix_print.py +++ b/Lib/lib2to3/fixes/fix_print.py @@ -44,10 +44,10 @@ class FixPrint(fixer_base.ConditionalFix): if bare_print: # Special-case print all by itself - bare_print.replace(Call(Name("print"), [], + bare_print.replace(Call(Name(u"print"), [], prefix=bare_print.get_prefix())) return - assert node.children[0] == Name("print") + assert node.children[0] == Name(u"print") args = node.children[1:] if len(args) == 1 and parend_expr.match(args[0]): # We don't want to keep sticking parens around an @@ -58,33 +58,33 @@ class FixPrint(fixer_base.ConditionalFix): if args and args[-1] == Comma(): args = args[:-1] end = " " - if args and args[0] == pytree.Leaf(token.RIGHTSHIFT, ">>"): + if args and args[0] == pytree.Leaf(token.RIGHTSHIFT, u">>"): assert len(args) >= 2 file = args[1].clone() args = args[3:] # Strip a possible comma after the file expression # 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("") + l_args[0].set_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, "sep", String(repr(sep))) + self.add_kwarg(l_args, u"sep", String(repr(sep))) if end is not None: - self.add_kwarg(l_args, "end", String(repr(end))) + self.add_kwarg(l_args, u"end", String(repr(end))) if file is not None: - self.add_kwarg(l_args, "file", file) - n_stmt = Call(Name("print"), l_args) + self.add_kwarg(l_args, u"file", file) + n_stmt = Call(Name(u"print"), l_args) n_stmt.set_prefix(node.get_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("") + n_expr.set_prefix(u"") n_argument = pytree.Node(self.syms.argument, (Name(s_kwd), - pytree.Leaf(token.EQUAL, "="), + pytree.Leaf(token.EQUAL, u"="), n_expr)) if l_nodes: l_nodes.append(Comma()) - n_argument.set_prefix(" ") + n_argument.set_prefix(u" ") l_nodes.append(n_argument) diff --git a/Lib/lib2to3/fixes/fix_raise.py b/Lib/lib2to3/fixes/fix_raise.py index be785f5..e698912 100644 --- a/Lib/lib2to3/fixes/fix_raise.py +++ b/Lib/lib2to3/fixes/fix_raise.py @@ -56,7 +56,7 @@ class FixRaise(fixer_base.BaseFix): if "val" not in results: # One-argument raise - new = pytree.Node(syms.raise_stmt, [Name("raise"), exc]) + new = pytree.Node(syms.raise_stmt, [Name(u"raise"), exc]) new.set_prefix(node.get_prefix()) return new @@ -64,19 +64,19 @@ class FixRaise(fixer_base.BaseFix): if is_tuple(val): args = [c.clone() for c in val.children[1:-1]] else: - val.set_prefix("") + val.set_prefix(u"") args = [val] if "tb" in results: tb = results["tb"].clone() - tb.set_prefix("") + tb.set_prefix(u"") e = Call(exc, args) - with_tb = Attr(e, Name('with_traceback')) + [ArgList([tb])] - new = pytree.Node(syms.simple_stmt, [Name("raise")] + with_tb) + 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()) return new else: return pytree.Node(syms.raise_stmt, - [Name("raise"), Call(exc, args)], + [Name(u"raise"), Call(exc, args)], prefix=node.get_prefix()) diff --git a/Lib/lib2to3/fixes/fix_raw_input.py b/Lib/lib2to3/fixes/fix_raw_input.py index 53e7a32..b95ac87 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("input", prefix=name.get_prefix())) + name.replace(Name(u"input", prefix=name.get_prefix())) diff --git a/Lib/lib2to3/fixes/fix_reduce.py b/Lib/lib2to3/fixes/fix_reduce.py index 89fa2b4..98037f4 100644 --- a/Lib/lib2to3/fixes/fix_reduce.py +++ b/Lib/lib2to3/fixes/fix_reduce.py @@ -30,4 +30,4 @@ class FixReduce(fixer_base.BaseFix): """ def transform(self, node, results): - touch_import('functools', 'reduce', node) + touch_import(u'functools', u'reduce', node) diff --git a/Lib/lib2to3/fixes/fix_renames.py b/Lib/lib2to3/fixes/fix_renames.py index 33d4746..0f4bcaf 100644 --- a/Lib/lib2to3/fixes/fix_renames.py +++ b/Lib/lib2to3/fixes/fix_renames.py @@ -65,5 +65,5 @@ class FixRenames(fixer_base.BaseFix): #import_mod = results.get("module") if mod_name and attr_name: - new_attr = LOOKUP[(mod_name.value, attr_name.value)] + new_attr = unicode(LOOKUP[(mod_name.value, attr_name.value)]) attr_name.replace(Name(new_attr, prefix=attr_name.get_prefix())) diff --git a/Lib/lib2to3/fixes/fix_repr.py b/Lib/lib2to3/fixes/fix_repr.py index 0bc6ba6..07974ff 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("repr"), [expr], prefix=node.get_prefix()) + return Call(Name(u"repr"), [expr], prefix=node.get_prefix()) diff --git a/Lib/lib2to3/fixes/fix_set_literal.py b/Lib/lib2to3/fixes/fix_set_literal.py index 35743d2..97b318d 100644 --- a/Lib/lib2to3/fixes/fix_set_literal.py +++ b/Lib/lib2to3/fixes/fix_set_literal.py @@ -34,9 +34,9 @@ class FixSetLiteral(fixer_base.BaseFix): items = results["items"] # Build the contents of the literal - literal = [pytree.Leaf(token.LBRACE, "{")] + literal = [pytree.Leaf(token.LBRACE, u"{")] literal.extend(n.clone() for n in items.children) - literal.append(pytree.Leaf(token.RBRACE, "}")) + 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()) maker = pytree.Node(syms.dictsetmaker, literal) diff --git a/Lib/lib2to3/fixes/fix_standarderror.py b/Lib/lib2to3/fixes/fix_standarderror.py index 4f87014..44cbb57 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("Exception", prefix=node.get_prefix()) + return Name(u"Exception", prefix=node.get_prefix()) diff --git a/Lib/lib2to3/fixes/fix_sys_exc.py b/Lib/lib2to3/fixes/fix_sys_exc.py index 18d9363..936183f 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("exc_info"), prefix=sys_attr.get_prefix()) - attr = Attr(Name("sys"), call) + call = Call(Name(u"exc_info"), prefix=sys_attr.get_prefix()) + attr = Attr(Name(u"sys"), call) attr[1].children[0].set_prefix(results["dot"].get_prefix()) attr.append(Subscript(index)) return Node(syms.power, attr, prefix=node.get_prefix()) diff --git a/Lib/lib2to3/fixes/fix_throw.py b/Lib/lib2to3/fixes/fix_throw.py index bf86d84..90ffc64 100644 --- a/Lib/lib2to3/fixes/fix_throw.py +++ b/Lib/lib2to3/fixes/fix_throw.py @@ -32,7 +32,7 @@ class FixThrow(fixer_base.BaseFix): return # Leave "g.throw(E)" alone - val = results.get("val") + val = results.get(u"val") if val is None: return @@ -40,17 +40,17 @@ class FixThrow(fixer_base.BaseFix): if is_tuple(val): args = [c.clone() for c in val.children[1:-1]] else: - val.set_prefix("") + val.set_prefix(u"") args = [val] throw_args = results["args"] if "tb" in results: tb = results["tb"].clone() - tb.set_prefix("") + tb.set_prefix(u"") e = Call(exc, args) - with_tb = Attr(e, Name('with_traceback')) + [ArgList([tb])] + with_tb = Attr(e, Name(u'with_traceback')) + [ArgList([tb])] throw_args.replace(pytree.Node(syms.power, with_tb)) else: throw_args.replace(Call(exc, args)) diff --git a/Lib/lib2to3/fixes/fix_tuple_params.py b/Lib/lib2to3/fixes/fix_tuple_params.py index fb29f5c..6628518 100644 --- a/Lib/lib2to3/fixes/fix_tuple_params.py +++ b/Lib/lib2to3/fixes/fix_tuple_params.py @@ -55,7 +55,7 @@ class FixTupleParams(fixer_base.BaseFix): else: start = 0 indent = "; " - end = pytree.Leaf(token.INDENT, "") + end = pytree.Leaf(token.INDENT, u"") # We need access to self for new_name(), and making this a method # doesn't feel right. Closing over self and new_lines makes the @@ -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("") + arg.set_prefix(u"") stmt = Assign(arg, n.clone()) if add_prefix: - n.set_prefix(" ") + n.set_prefix(u" ") tuple_arg.replace(n) new_lines.append(pytree.Node(syms.simple_stmt, [stmt, end.clone()])) @@ -91,7 +91,7 @@ class FixTupleParams(fixer_base.BaseFix): # TODO(cwinter) suite-cleanup after = start if start == 0: - new_lines[0].set_prefix(" ") + new_lines[0].set_prefix(u" ") elif is_docstring(suite[0].children[start]): new_lines[0].set_prefix(indent) after = start + 1 @@ -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(" ") + inner.set_prefix(u" ") args.replace(inner) return @@ -117,7 +117,7 @@ class FixTupleParams(fixer_base.BaseFix): to_index = map_to_index(params) tup_name = self.new_name(tuple_name(params)) - new_param = Name(tup_name, prefix=" ") + new_param = Name(tup_name, prefix=u" ") args.replace(new_param.clone()) for n in body.post_order(): if n.type == token.NAME and n.value in to_index: @@ -166,4 +166,4 @@ def tuple_name(param_list): l.append(tuple_name(obj)) else: l.append(obj) - return "_".join(l) + return u"_".join(l) diff --git a/Lib/lib2to3/fixes/fix_types.py b/Lib/lib2to3/fixes/fix_types.py index 445f1b2..9327248 100644 --- a/Lib/lib2to3/fixes/fix_types.py +++ b/Lib/lib2to3/fixes/fix_types.py @@ -56,7 +56,7 @@ class FixTypes(fixer_base.BaseFix): PATTERN = '|'.join(_pats) def transform(self, node, results): - new_value = _TYPE_MAPPING.get(results["name"].value) + new_value = unicode(_TYPE_MAPPING.get(results["name"].value)) if new_value: return Name(new_value, prefix=node.get_prefix()) return None diff --git a/Lib/lib2to3/fixes/fix_unicode.py b/Lib/lib2to3/fixes/fix_unicode.py index 7f5cc80..580e82d 100644 --- a/Lib/lib2to3/fixes/fix_unicode.py +++ b/Lib/lib2to3/fixes/fix_unicode.py @@ -12,17 +12,17 @@ class FixUnicode(fixer_base.BaseFix): def transform(self, node, results): if node.type == token.NAME: - if node.value == "unicode": + if node.value == u"unicode": new = node.clone() - new.value = "str" + new.value = u"str" return new - if node.value == "unichr": + if node.value == u"unichr": new = node.clone() - new.value = "chr" + new.value = u"chr" return new # XXX Warn when __unicode__ found? elif node.type == token.STRING: - if re.match(r"[uU][rR]?[\'\"]", node.value): + if re.match(ur"[uU][rR]?[\'\"]", node.value): new = node.clone() new.value = new.value[1:] return new diff --git a/Lib/lib2to3/fixes/fix_ws_comma.py b/Lib/lib2to3/fixes/fix_ws_comma.py index e493498..b5bfd8c 100644 --- a/Lib/lib2to3/fixes/fix_ws_comma.py +++ b/Lib/lib2to3/fixes/fix_ws_comma.py @@ -17,8 +17,8 @@ class FixWsComma(fixer_base.BaseFix): any<(not(',') any)+ ',' ((not(',') any)+ ',')* [not(',') any]> """ - COMMA = pytree.Leaf(token.COMMA, ",") - COLON = pytree.Leaf(token.COLON, ":") + COMMA = pytree.Leaf(token.COMMA, u",") + COLON = pytree.Leaf(token.COLON, u":") SEPS = (COMMA, COLON) def transform(self, node, results): @@ -27,13 +27,13 @@ class FixWsComma(fixer_base.BaseFix): 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("") + if prefix.isspace() and u"\n" not in prefix: + child.set_prefix(u"") comma = True else: if comma: prefix = child.get_prefix() if not prefix: - child.set_prefix(" ") + child.set_prefix(u" ") comma = False return new diff --git a/Lib/lib2to3/fixes/fix_xrange.py b/Lib/lib2to3/fixes/fix_xrange.py index ca8f21a..c472a03 100644 --- a/Lib/lib2to3/fixes/fix_xrange.py +++ b/Lib/lib2to3/fixes/fix_xrange.py @@ -19,22 +19,22 @@ class FixXrange(fixer_base.BaseFix): def transform(self, node, results): name = results["name"] - if name.value == "xrange": + if name.value == u"xrange": return self.transform_xrange(node, results) - elif name.value == "range": + elif name.value == u"range": return self.transform_range(node, results) else: raise ValueError(repr(name)) def transform_xrange(self, node, results): name = results["name"] - name.replace(Name("range", prefix=name.get_prefix())) + name.replace(Name(u"range", prefix=name.get_prefix())) def transform_range(self, node, results): if not self.in_special_context(node): - range_call = Call(Name("range"), [results["args"].clone()]) + range_call = Call(Name(u"range"), [results["args"].clone()]) # Encase the range call in list(). - list_call = Call(Name("list"), [range_call], + list_call = Call(Name(u"list"), [range_call], prefix=node.get_prefix()) # Put things that were after the range() call after the list call. for n in results["rest"]: diff --git a/Lib/lib2to3/fixes/fix_xreadlines.py b/Lib/lib2to3/fixes/fix_xreadlines.py index 2d3f3c8..4880751 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("__iter__", prefix=no_call.get_prefix())) + no_call.replace(Name(u"__iter__", prefix=no_call.get_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 08296c0..e990842 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("") - new = Call(Name("list"), [new]) + new.set_prefix(u"") + new = Call(Name(u"list"), [new]) new.set_prefix(node.get_prefix()) return new |