diff options
Diffstat (limited to 'Lib/lib2to3/fixes/fix_metaclass.py')
-rw-r--r-- | Lib/lib2to3/fixes/fix_metaclass.py | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/Lib/lib2to3/fixes/fix_metaclass.py b/Lib/lib2to3/fixes/fix_metaclass.py index d1cd10d..45f9937 100644 --- a/Lib/lib2to3/fixes/fix_metaclass.py +++ b/Lib/lib2to3/fixes/fix_metaclass.py @@ -1,6 +1,6 @@ """Fixer for __metaclass__ = X -> (metaclass=X) methods. - The various forms of classef (inherits nothing, inherits once, inherits + The various forms of classef (inherits nothing, inherits once, inherints many) don't parse the same in the CST so we look at ALL classes for a __metaclass__ and if we find one normalize the inherits to all be an arglist. @@ -20,7 +20,7 @@ # Local imports from .. import fixer_base from ..pygram import token -from ..fixer_util import syms, Node, Leaf +from ..fixer_util import Name, syms, Node, Leaf def has_metaclass(parent): @@ -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 an assignment to __metaclass__. fixup_simple_stmt(node, i, simple_node) remove_trailing_newline(simple_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.prefix = '' + node.prefix = u'' return else: kids.extend(node.children[::-1]) @@ -183,9 +183,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") @@ -195,16 +195,16 @@ class FixMetaclass(fixer_base.BaseFix): orig_meta_prefix = meta_txt.prefix if arglist.children: - arglist.append_child(Leaf(token.COMMA, ',')) - meta_txt.prefix = ' ' + arglist.append_child(Leaf(token.COMMA, u',')) + meta_txt.prefix = u' ' else: - meta_txt.prefix = '' + 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].prefix = '' - expr_stmt.children[2].prefix = '' + expr_stmt.children[1].prefix = u'' + expr_stmt.children[2].prefix = u'' arglist.append_child(last_metaclass) @@ -214,15 +214,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.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')) |