2008-09-13 14:43:19 -03:00
|
|
|
"""Fixer for __metaclass__ = X -> (metaclass=X) methods.
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
For one-liner classes ('class X: pass') there is no indent/dedent so
|
|
|
|
we normalize those into having a suite.
|
|
|
|
|
|
|
|
Moving the __metaclass__ into the classdef can also cause the class
|
|
|
|
body to be empty so there is some special casing for that as well.
|
|
|
|
|
|
|
|
This fixer also tries very hard to keep original indenting and spacing
|
|
|
|
in all those corner cases.
|
|
|
|
|
|
|
|
"""
|
|
|
|
# Author: Jack Diederich
|
|
|
|
|
|
|
|
# Local imports
|
|
|
|
from .. import fixer_base
|
|
|
|
from ..pygram import token
|
|
|
|
from ..fixer_util import Name, syms, Node, Leaf
|
|
|
|
|
|
|
|
|
|
|
|
def has_metaclass(parent):
|
|
|
|
""" we have to check the cls_node without changing it.
|
|
|
|
There are two possiblities:
|
|
|
|
1) clsdef => suite => simple_stmt => expr_stmt => Leaf('__meta')
|
|
|
|
2) clsdef => simple_stmt => expr_stmt => Leaf('__meta')
|
|
|
|
"""
|
|
|
|
for node in parent.children:
|
|
|
|
if node.type == syms.suite:
|
|
|
|
return has_metaclass(node)
|
|
|
|
elif node.type == syms.simple_stmt and node.children:
|
|
|
|
expr_node = node.children[0]
|
|
|
|
if expr_node.type == syms.expr_stmt and expr_node.children:
|
Merged revisions 66985,67170,67173,67177-67179 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r66985 | benjamin.peterson | 2008-10-20 16:43:46 -0500 (Mon, 20 Oct 2008) | 1 line
no need to use nested try, except, finally
........
r67170 | benjamin.peterson | 2008-11-08 12:28:31 -0600 (Sat, 08 Nov 2008) | 1 line
fix #4271: fix_imports didn't recognize imports with parenthesis (ie from x import (a, b))
........
r67173 | benjamin.peterson | 2008-11-08 17:42:08 -0600 (Sat, 08 Nov 2008) | 1 line
consolidate test
........
r67177 | benjamin.peterson | 2008-11-09 21:52:52 -0600 (Sun, 09 Nov 2008) | 1 line
let the metclass fixer handle complex assignments in the class body gracefully
........
r67178 | benjamin.peterson | 2008-11-10 15:26:43 -0600 (Mon, 10 Nov 2008) | 1 line
the metaclass fixers shouldn't die when bases are not a simple name
........
r67179 | benjamin.peterson | 2008-11-10 15:29:58 -0600 (Mon, 10 Nov 2008) | 1 line
allow the fix_import pattern to catch from imports with parenthesis
........
2008-11-10 18:11:12 -04:00
|
|
|
left_side = expr_node.children[0]
|
|
|
|
if isinstance(left_side, Leaf) and \
|
|
|
|
left_side.value == '__metaclass__':
|
2008-09-13 14:43:19 -03:00
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
def fixup_parse_tree(cls_node):
|
|
|
|
""" one-line classes don't get a suite in the parse tree so we add
|
|
|
|
one to normalize the tree
|
|
|
|
"""
|
|
|
|
for node in cls_node.children:
|
|
|
|
if node.type == syms.suite:
|
|
|
|
# already in the prefered format, do nothing
|
|
|
|
return
|
|
|
|
|
|
|
|
# !%@#! oneliners have no suite node, we have to fake one up
|
|
|
|
for i, node in enumerate(cls_node.children):
|
|
|
|
if node.type == token.COLON:
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
raise ValueError("No class suite and no ':'!")
|
|
|
|
|
|
|
|
# move everything into a suite node
|
|
|
|
suite = Node(syms.suite, [])
|
|
|
|
while cls_node.children[i+1:]:
|
|
|
|
move_node = cls_node.children[i+1]
|
|
|
|
suite.append_child(move_node.clone())
|
|
|
|
move_node.remove()
|
|
|
|
cls_node.append_child(suite)
|
|
|
|
node = suite
|
|
|
|
|
|
|
|
|
|
|
|
def fixup_simple_stmt(parent, i, stmt_node):
|
|
|
|
""" if there is a semi-colon all the parts count as part of the same
|
|
|
|
simple_stmt. We just want the __metaclass__ part so we move
|
|
|
|
everything efter the semi-colon into its own simple_stmt node
|
|
|
|
"""
|
|
|
|
for semi_ind, node in enumerate(stmt_node.children):
|
|
|
|
if node.type == token.SEMI: # *sigh*
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
return
|
|
|
|
|
|
|
|
node.remove() # kill the semicolon
|
|
|
|
new_expr = Node(syms.expr_stmt, [])
|
|
|
|
new_stmt = Node(syms.simple_stmt, [new_expr])
|
|
|
|
while stmt_node.children[semi_ind:]:
|
|
|
|
move_node = stmt_node.children[semi_ind]
|
|
|
|
new_expr.append_child(move_node.clone())
|
|
|
|
move_node.remove()
|
|
|
|
parent.insert_child(i, new_stmt)
|
|
|
|
new_leaf1 = new_stmt.children[0].children[0]
|
|
|
|
old_leaf1 = stmt_node.children[0].children[0]
|
Merged revisions 72523,72950-72951,72994,73003,73033,73036-73040,73091-73093,73096,73179-73181,73192,73231,73244,73255-73256,73365 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r72523 | benjamin.peterson | 2009-05-09 14:42:26 -0500 (Sat, 09 May 2009) | 1 line
remove parenthesis
........
r72950 | benjamin.peterson | 2009-05-26 18:19:45 -0500 (Tue, 26 May 2009) | 1 line
remove unused imports
........
r72951 | benjamin.peterson | 2009-05-26 18:27:00 -0500 (Tue, 26 May 2009) | 1 line
this is no longer executable
........
r72994 | benjamin.peterson | 2009-05-28 15:32:54 -0500 (Thu, 28 May 2009) | 1 line
fix test_all_fixers on Windows #6134
........
r73003 | benjamin.peterson | 2009-05-28 21:57:28 -0500 (Thu, 28 May 2009) | 4 lines
make 2to3 test utilities easier to use with other applications (3to2)
Patch by Joe Amenta
........
r73033 | benjamin.peterson | 2009-05-29 16:58:32 -0500 (Fri, 29 May 2009) | 1 line
update grammar for multi with statement
........
r73036 | benjamin.peterson | 2009-05-29 17:33:20 -0500 (Fri, 29 May 2009) | 1 line
simplify fix_unicode
........
r73037 | benjamin.peterson | 2009-05-29 17:53:03 -0500 (Fri, 29 May 2009) | 1 line
add custom error for pattern syntax errors
........
r73038 | benjamin.peterson | 2009-05-29 17:55:00 -0500 (Fri, 29 May 2009) | 1 line
complain if details are attached to a token
........
r73039 | benjamin.peterson | 2009-05-29 18:00:28 -0500 (Fri, 29 May 2009) | 1 line
add a test for whitespace
........
r73040 | benjamin.peterson | 2009-05-29 18:01:17 -0500 (Fri, 29 May 2009) | 1 line
a fix for emacs highlighting
........
r73091 | benjamin.peterson | 2009-05-31 20:55:25 -0500 (Sun, 31 May 2009) | 1 line
deprecate set_prefix() and get_prefix() in favor of a prefix property
........
r73092 | benjamin.peterson | 2009-05-31 21:00:51 -0500 (Sun, 31 May 2009) | 1 line
change hideous java naming scheme
........
r73093 | benjamin.peterson | 2009-05-31 21:01:39 -0500 (Sun, 31 May 2009) | 1 line
remove dated comment
........
r73096 | benjamin.peterson | 2009-05-31 21:40:53 -0500 (Sun, 31 May 2009) | 1 line
group tests
........
r73179 | benjamin.peterson | 2009-06-03 13:09:53 -0500 (Wed, 03 Jun 2009) | 1 line
handle the case where there's multiple trailers #6185
........
r73180 | benjamin.peterson | 2009-06-03 13:18:05 -0500 (Wed, 03 Jun 2009) | 1 line
scrap __main__ section
........
r73181 | benjamin.peterson | 2009-06-03 13:24:48 -0500 (Wed, 03 Jun 2009) | 1 line
remove shebang lines and __main__ sections
........
r73192 | benjamin.peterson | 2009-06-03 19:16:30 -0500 (Wed, 03 Jun 2009) | 4 lines
actually test something here
Thanks to Joe Amenta for noticing.y
........
r73231 | benjamin.peterson | 2009-06-04 13:38:50 -0500 (Thu, 04 Jun 2009) | 1 line
remove unused variable
........
r73244 | benjamin.peterson | 2009-06-05 08:39:25 -0500 (Fri, 05 Jun 2009) | 1 line
allow fixers to give different options in setUp
........
r73255 | benjamin.peterson | 2009-06-06 11:23:46 -0500 (Sat, 06 Jun 2009) | 1 line
fix the except fixer on one line suites #6222
........
r73256 | benjamin.peterson | 2009-06-06 11:27:40 -0500 (Sat, 06 Jun 2009) | 1 line
test one-line else and finally clauses
........
r73365 | benjamin.peterson | 2009-06-11 17:01:32 -0500 (Thu, 11 Jun 2009) | 1 line
normalize whitespace
........
2009-06-11 19:06:46 -03:00
|
|
|
new_leaf1.prefix = old_leaf1.prefix
|
2008-09-13 14:43:19 -03:00
|
|
|
|
|
|
|
|
|
|
|
def remove_trailing_newline(node):
|
|
|
|
if node.children and node.children[-1].type == token.NEWLINE:
|
|
|
|
node.children[-1].remove()
|
|
|
|
|
|
|
|
|
|
|
|
def find_metas(cls_node):
|
|
|
|
# find the suite node (Mmm, sweet nodes)
|
|
|
|
for node in cls_node.children:
|
|
|
|
if node.type == syms.suite:
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
raise ValueError("No class suite!")
|
|
|
|
|
|
|
|
# look for simple_stmt[ expr_stmt[ Leaf('__metaclass__') ] ]
|
|
|
|
for i, simple_node in list(enumerate(node.children)):
|
|
|
|
if simple_node.type == syms.simple_stmt and simple_node.children:
|
|
|
|
expr_node = simple_node.children[0]
|
|
|
|
if expr_node.type == syms.expr_stmt and expr_node.children:
|
2008-11-25 00:07:45 -04:00
|
|
|
# Check if the expr_node is a simple assignment.
|
|
|
|
left_node = expr_node.children[0]
|
|
|
|
if isinstance(left_node, Leaf) and \
|
2009-05-08 22:01:14 -03:00
|
|
|
left_node.value == u'__metaclass__':
|
2008-11-25 00:07:45 -04:00
|
|
|
# We found a assignment to __metaclass__.
|
2008-09-13 14:43:19 -03:00
|
|
|
fixup_simple_stmt(node, i, simple_node)
|
|
|
|
remove_trailing_newline(simple_node)
|
|
|
|
yield (node, i, simple_node)
|
|
|
|
|
|
|
|
|
|
|
|
def fixup_indent(suite):
|
|
|
|
""" If an INDENT is followed by a thing with a prefix then nuke the prefix
|
|
|
|
Otherwise we get in trouble when removing __metaclass__ at suite start
|
|
|
|
"""
|
|
|
|
kids = suite.children[::-1]
|
|
|
|
# find the first indent
|
|
|
|
while kids:
|
|
|
|
node = kids.pop()
|
|
|
|
if node.type == token.INDENT:
|
|
|
|
break
|
|
|
|
|
|
|
|
# find the first Leaf
|
|
|
|
while kids:
|
|
|
|
node = kids.pop()
|
|
|
|
if isinstance(node, Leaf) and node.type != token.DEDENT:
|
|
|
|
if node.prefix:
|
Merged revisions 72523,72950-72951,72994,73003,73033,73036-73040,73091-73093,73096,73179-73181,73192,73231,73244,73255-73256,73365 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r72523 | benjamin.peterson | 2009-05-09 14:42:26 -0500 (Sat, 09 May 2009) | 1 line
remove parenthesis
........
r72950 | benjamin.peterson | 2009-05-26 18:19:45 -0500 (Tue, 26 May 2009) | 1 line
remove unused imports
........
r72951 | benjamin.peterson | 2009-05-26 18:27:00 -0500 (Tue, 26 May 2009) | 1 line
this is no longer executable
........
r72994 | benjamin.peterson | 2009-05-28 15:32:54 -0500 (Thu, 28 May 2009) | 1 line
fix test_all_fixers on Windows #6134
........
r73003 | benjamin.peterson | 2009-05-28 21:57:28 -0500 (Thu, 28 May 2009) | 4 lines
make 2to3 test utilities easier to use with other applications (3to2)
Patch by Joe Amenta
........
r73033 | benjamin.peterson | 2009-05-29 16:58:32 -0500 (Fri, 29 May 2009) | 1 line
update grammar for multi with statement
........
r73036 | benjamin.peterson | 2009-05-29 17:33:20 -0500 (Fri, 29 May 2009) | 1 line
simplify fix_unicode
........
r73037 | benjamin.peterson | 2009-05-29 17:53:03 -0500 (Fri, 29 May 2009) | 1 line
add custom error for pattern syntax errors
........
r73038 | benjamin.peterson | 2009-05-29 17:55:00 -0500 (Fri, 29 May 2009) | 1 line
complain if details are attached to a token
........
r73039 | benjamin.peterson | 2009-05-29 18:00:28 -0500 (Fri, 29 May 2009) | 1 line
add a test for whitespace
........
r73040 | benjamin.peterson | 2009-05-29 18:01:17 -0500 (Fri, 29 May 2009) | 1 line
a fix for emacs highlighting
........
r73091 | benjamin.peterson | 2009-05-31 20:55:25 -0500 (Sun, 31 May 2009) | 1 line
deprecate set_prefix() and get_prefix() in favor of a prefix property
........
r73092 | benjamin.peterson | 2009-05-31 21:00:51 -0500 (Sun, 31 May 2009) | 1 line
change hideous java naming scheme
........
r73093 | benjamin.peterson | 2009-05-31 21:01:39 -0500 (Sun, 31 May 2009) | 1 line
remove dated comment
........
r73096 | benjamin.peterson | 2009-05-31 21:40:53 -0500 (Sun, 31 May 2009) | 1 line
group tests
........
r73179 | benjamin.peterson | 2009-06-03 13:09:53 -0500 (Wed, 03 Jun 2009) | 1 line
handle the case where there's multiple trailers #6185
........
r73180 | benjamin.peterson | 2009-06-03 13:18:05 -0500 (Wed, 03 Jun 2009) | 1 line
scrap __main__ section
........
r73181 | benjamin.peterson | 2009-06-03 13:24:48 -0500 (Wed, 03 Jun 2009) | 1 line
remove shebang lines and __main__ sections
........
r73192 | benjamin.peterson | 2009-06-03 19:16:30 -0500 (Wed, 03 Jun 2009) | 4 lines
actually test something here
Thanks to Joe Amenta for noticing.y
........
r73231 | benjamin.peterson | 2009-06-04 13:38:50 -0500 (Thu, 04 Jun 2009) | 1 line
remove unused variable
........
r73244 | benjamin.peterson | 2009-06-05 08:39:25 -0500 (Fri, 05 Jun 2009) | 1 line
allow fixers to give different options in setUp
........
r73255 | benjamin.peterson | 2009-06-06 11:23:46 -0500 (Sat, 06 Jun 2009) | 1 line
fix the except fixer on one line suites #6222
........
r73256 | benjamin.peterson | 2009-06-06 11:27:40 -0500 (Sat, 06 Jun 2009) | 1 line
test one-line else and finally clauses
........
r73365 | benjamin.peterson | 2009-06-11 17:01:32 -0500 (Thu, 11 Jun 2009) | 1 line
normalize whitespace
........
2009-06-11 19:06:46 -03:00
|
|
|
node.prefix = u''
|
2008-09-13 14:43:19 -03:00
|
|
|
return
|
|
|
|
else:
|
|
|
|
kids.extend(node.children[::-1])
|
|
|
|
|
|
|
|
|
|
|
|
class FixMetaclass(fixer_base.BaseFix):
|
|
|
|
|
|
|
|
PATTERN = """
|
|
|
|
classdef<any*>
|
|
|
|
"""
|
|
|
|
|
|
|
|
def transform(self, node, results):
|
|
|
|
if not has_metaclass(node):
|
2010-01-31 21:15:39 -04:00
|
|
|
return
|
2008-09-13 14:43:19 -03:00
|
|
|
|
|
|
|
fixup_parse_tree(node)
|
|
|
|
|
|
|
|
# find metaclasses, keep the last one
|
|
|
|
last_metaclass = None
|
|
|
|
for suite, i, stmt in find_metas(node):
|
|
|
|
last_metaclass = stmt
|
|
|
|
stmt.remove()
|
|
|
|
|
|
|
|
text_type = node.children[0].type # always Leaf(nnn, 'class')
|
|
|
|
|
|
|
|
# figure out what kind of classdef we have
|
|
|
|
if len(node.children) == 7:
|
|
|
|
# Node(classdef, ['class', 'name', '(', arglist, ')', ':', suite])
|
|
|
|
# 0 1 2 3 4 5 6
|
|
|
|
if node.children[3].type == syms.arglist:
|
|
|
|
arglist = node.children[3]
|
|
|
|
# Node(classdef, ['class', 'name', '(', 'Parent', ')', ':', suite])
|
Merged revisions 66985,67170,67173,67177-67179 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r66985 | benjamin.peterson | 2008-10-20 16:43:46 -0500 (Mon, 20 Oct 2008) | 1 line
no need to use nested try, except, finally
........
r67170 | benjamin.peterson | 2008-11-08 12:28:31 -0600 (Sat, 08 Nov 2008) | 1 line
fix #4271: fix_imports didn't recognize imports with parenthesis (ie from x import (a, b))
........
r67173 | benjamin.peterson | 2008-11-08 17:42:08 -0600 (Sat, 08 Nov 2008) | 1 line
consolidate test
........
r67177 | benjamin.peterson | 2008-11-09 21:52:52 -0600 (Sun, 09 Nov 2008) | 1 line
let the metclass fixer handle complex assignments in the class body gracefully
........
r67178 | benjamin.peterson | 2008-11-10 15:26:43 -0600 (Mon, 10 Nov 2008) | 1 line
the metaclass fixers shouldn't die when bases are not a simple name
........
r67179 | benjamin.peterson | 2008-11-10 15:29:58 -0600 (Mon, 10 Nov 2008) | 1 line
allow the fix_import pattern to catch from imports with parenthesis
........
2008-11-10 18:11:12 -04:00
|
|
|
else:
|
2008-09-13 14:43:19 -03:00
|
|
|
parent = node.children[3].clone()
|
|
|
|
arglist = Node(syms.arglist, [parent])
|
|
|
|
node.set_child(3, arglist)
|
|
|
|
elif len(node.children) == 6:
|
|
|
|
# Node(classdef, ['class', 'name', '(', ')', ':', suite])
|
|
|
|
# 0 1 2 3 4 5
|
|
|
|
arglist = Node(syms.arglist, [])
|
|
|
|
node.insert_child(3, arglist)
|
|
|
|
elif len(node.children) == 4:
|
|
|
|
# Node(classdef, ['class', 'name', ':', suite])
|
|
|
|
# 0 1 2 3
|
|
|
|
arglist = Node(syms.arglist, [])
|
2009-05-08 22:01:14 -03:00
|
|
|
node.insert_child(2, Leaf(token.RPAR, u')'))
|
2008-09-13 14:43:19 -03:00
|
|
|
node.insert_child(2, arglist)
|
2009-05-08 22:01:14 -03:00
|
|
|
node.insert_child(2, Leaf(token.LPAR, u'('))
|
2008-09-13 14:43:19 -03:00
|
|
|
else:
|
|
|
|
raise ValueError("Unexpected class definition")
|
|
|
|
|
|
|
|
# now stick the metaclass in the arglist
|
|
|
|
meta_txt = last_metaclass.children[0].children[0]
|
|
|
|
meta_txt.value = 'metaclass'
|
Merged revisions 72523,72950-72951,72994,73003,73033,73036-73040,73091-73093,73096,73179-73181,73192,73231,73244,73255-73256,73365 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r72523 | benjamin.peterson | 2009-05-09 14:42:26 -0500 (Sat, 09 May 2009) | 1 line
remove parenthesis
........
r72950 | benjamin.peterson | 2009-05-26 18:19:45 -0500 (Tue, 26 May 2009) | 1 line
remove unused imports
........
r72951 | benjamin.peterson | 2009-05-26 18:27:00 -0500 (Tue, 26 May 2009) | 1 line
this is no longer executable
........
r72994 | benjamin.peterson | 2009-05-28 15:32:54 -0500 (Thu, 28 May 2009) | 1 line
fix test_all_fixers on Windows #6134
........
r73003 | benjamin.peterson | 2009-05-28 21:57:28 -0500 (Thu, 28 May 2009) | 4 lines
make 2to3 test utilities easier to use with other applications (3to2)
Patch by Joe Amenta
........
r73033 | benjamin.peterson | 2009-05-29 16:58:32 -0500 (Fri, 29 May 2009) | 1 line
update grammar for multi with statement
........
r73036 | benjamin.peterson | 2009-05-29 17:33:20 -0500 (Fri, 29 May 2009) | 1 line
simplify fix_unicode
........
r73037 | benjamin.peterson | 2009-05-29 17:53:03 -0500 (Fri, 29 May 2009) | 1 line
add custom error for pattern syntax errors
........
r73038 | benjamin.peterson | 2009-05-29 17:55:00 -0500 (Fri, 29 May 2009) | 1 line
complain if details are attached to a token
........
r73039 | benjamin.peterson | 2009-05-29 18:00:28 -0500 (Fri, 29 May 2009) | 1 line
add a test for whitespace
........
r73040 | benjamin.peterson | 2009-05-29 18:01:17 -0500 (Fri, 29 May 2009) | 1 line
a fix for emacs highlighting
........
r73091 | benjamin.peterson | 2009-05-31 20:55:25 -0500 (Sun, 31 May 2009) | 1 line
deprecate set_prefix() and get_prefix() in favor of a prefix property
........
r73092 | benjamin.peterson | 2009-05-31 21:00:51 -0500 (Sun, 31 May 2009) | 1 line
change hideous java naming scheme
........
r73093 | benjamin.peterson | 2009-05-31 21:01:39 -0500 (Sun, 31 May 2009) | 1 line
remove dated comment
........
r73096 | benjamin.peterson | 2009-05-31 21:40:53 -0500 (Sun, 31 May 2009) | 1 line
group tests
........
r73179 | benjamin.peterson | 2009-06-03 13:09:53 -0500 (Wed, 03 Jun 2009) | 1 line
handle the case where there's multiple trailers #6185
........
r73180 | benjamin.peterson | 2009-06-03 13:18:05 -0500 (Wed, 03 Jun 2009) | 1 line
scrap __main__ section
........
r73181 | benjamin.peterson | 2009-06-03 13:24:48 -0500 (Wed, 03 Jun 2009) | 1 line
remove shebang lines and __main__ sections
........
r73192 | benjamin.peterson | 2009-06-03 19:16:30 -0500 (Wed, 03 Jun 2009) | 4 lines
actually test something here
Thanks to Joe Amenta for noticing.y
........
r73231 | benjamin.peterson | 2009-06-04 13:38:50 -0500 (Thu, 04 Jun 2009) | 1 line
remove unused variable
........
r73244 | benjamin.peterson | 2009-06-05 08:39:25 -0500 (Fri, 05 Jun 2009) | 1 line
allow fixers to give different options in setUp
........
r73255 | benjamin.peterson | 2009-06-06 11:23:46 -0500 (Sat, 06 Jun 2009) | 1 line
fix the except fixer on one line suites #6222
........
r73256 | benjamin.peterson | 2009-06-06 11:27:40 -0500 (Sat, 06 Jun 2009) | 1 line
test one-line else and finally clauses
........
r73365 | benjamin.peterson | 2009-06-11 17:01:32 -0500 (Thu, 11 Jun 2009) | 1 line
normalize whitespace
........
2009-06-11 19:06:46 -03:00
|
|
|
orig_meta_prefix = meta_txt.prefix
|
2008-09-13 14:43:19 -03:00
|
|
|
|
|
|
|
if arglist.children:
|
2009-05-08 22:01:14 -03:00
|
|
|
arglist.append_child(Leaf(token.COMMA, u','))
|
Merged revisions 72523,72950-72951,72994,73003,73033,73036-73040,73091-73093,73096,73179-73181,73192,73231,73244,73255-73256,73365 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r72523 | benjamin.peterson | 2009-05-09 14:42:26 -0500 (Sat, 09 May 2009) | 1 line
remove parenthesis
........
r72950 | benjamin.peterson | 2009-05-26 18:19:45 -0500 (Tue, 26 May 2009) | 1 line
remove unused imports
........
r72951 | benjamin.peterson | 2009-05-26 18:27:00 -0500 (Tue, 26 May 2009) | 1 line
this is no longer executable
........
r72994 | benjamin.peterson | 2009-05-28 15:32:54 -0500 (Thu, 28 May 2009) | 1 line
fix test_all_fixers on Windows #6134
........
r73003 | benjamin.peterson | 2009-05-28 21:57:28 -0500 (Thu, 28 May 2009) | 4 lines
make 2to3 test utilities easier to use with other applications (3to2)
Patch by Joe Amenta
........
r73033 | benjamin.peterson | 2009-05-29 16:58:32 -0500 (Fri, 29 May 2009) | 1 line
update grammar for multi with statement
........
r73036 | benjamin.peterson | 2009-05-29 17:33:20 -0500 (Fri, 29 May 2009) | 1 line
simplify fix_unicode
........
r73037 | benjamin.peterson | 2009-05-29 17:53:03 -0500 (Fri, 29 May 2009) | 1 line
add custom error for pattern syntax errors
........
r73038 | benjamin.peterson | 2009-05-29 17:55:00 -0500 (Fri, 29 May 2009) | 1 line
complain if details are attached to a token
........
r73039 | benjamin.peterson | 2009-05-29 18:00:28 -0500 (Fri, 29 May 2009) | 1 line
add a test for whitespace
........
r73040 | benjamin.peterson | 2009-05-29 18:01:17 -0500 (Fri, 29 May 2009) | 1 line
a fix for emacs highlighting
........
r73091 | benjamin.peterson | 2009-05-31 20:55:25 -0500 (Sun, 31 May 2009) | 1 line
deprecate set_prefix() and get_prefix() in favor of a prefix property
........
r73092 | benjamin.peterson | 2009-05-31 21:00:51 -0500 (Sun, 31 May 2009) | 1 line
change hideous java naming scheme
........
r73093 | benjamin.peterson | 2009-05-31 21:01:39 -0500 (Sun, 31 May 2009) | 1 line
remove dated comment
........
r73096 | benjamin.peterson | 2009-05-31 21:40:53 -0500 (Sun, 31 May 2009) | 1 line
group tests
........
r73179 | benjamin.peterson | 2009-06-03 13:09:53 -0500 (Wed, 03 Jun 2009) | 1 line
handle the case where there's multiple trailers #6185
........
r73180 | benjamin.peterson | 2009-06-03 13:18:05 -0500 (Wed, 03 Jun 2009) | 1 line
scrap __main__ section
........
r73181 | benjamin.peterson | 2009-06-03 13:24:48 -0500 (Wed, 03 Jun 2009) | 1 line
remove shebang lines and __main__ sections
........
r73192 | benjamin.peterson | 2009-06-03 19:16:30 -0500 (Wed, 03 Jun 2009) | 4 lines
actually test something here
Thanks to Joe Amenta for noticing.y
........
r73231 | benjamin.peterson | 2009-06-04 13:38:50 -0500 (Thu, 04 Jun 2009) | 1 line
remove unused variable
........
r73244 | benjamin.peterson | 2009-06-05 08:39:25 -0500 (Fri, 05 Jun 2009) | 1 line
allow fixers to give different options in setUp
........
r73255 | benjamin.peterson | 2009-06-06 11:23:46 -0500 (Sat, 06 Jun 2009) | 1 line
fix the except fixer on one line suites #6222
........
r73256 | benjamin.peterson | 2009-06-06 11:27:40 -0500 (Sat, 06 Jun 2009) | 1 line
test one-line else and finally clauses
........
r73365 | benjamin.peterson | 2009-06-11 17:01:32 -0500 (Thu, 11 Jun 2009) | 1 line
normalize whitespace
........
2009-06-11 19:06:46 -03:00
|
|
|
meta_txt.prefix = u' '
|
2008-09-13 14:43:19 -03:00
|
|
|
else:
|
Merged revisions 72523,72950-72951,72994,73003,73033,73036-73040,73091-73093,73096,73179-73181,73192,73231,73244,73255-73256,73365 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r72523 | benjamin.peterson | 2009-05-09 14:42:26 -0500 (Sat, 09 May 2009) | 1 line
remove parenthesis
........
r72950 | benjamin.peterson | 2009-05-26 18:19:45 -0500 (Tue, 26 May 2009) | 1 line
remove unused imports
........
r72951 | benjamin.peterson | 2009-05-26 18:27:00 -0500 (Tue, 26 May 2009) | 1 line
this is no longer executable
........
r72994 | benjamin.peterson | 2009-05-28 15:32:54 -0500 (Thu, 28 May 2009) | 1 line
fix test_all_fixers on Windows #6134
........
r73003 | benjamin.peterson | 2009-05-28 21:57:28 -0500 (Thu, 28 May 2009) | 4 lines
make 2to3 test utilities easier to use with other applications (3to2)
Patch by Joe Amenta
........
r73033 | benjamin.peterson | 2009-05-29 16:58:32 -0500 (Fri, 29 May 2009) | 1 line
update grammar for multi with statement
........
r73036 | benjamin.peterson | 2009-05-29 17:33:20 -0500 (Fri, 29 May 2009) | 1 line
simplify fix_unicode
........
r73037 | benjamin.peterson | 2009-05-29 17:53:03 -0500 (Fri, 29 May 2009) | 1 line
add custom error for pattern syntax errors
........
r73038 | benjamin.peterson | 2009-05-29 17:55:00 -0500 (Fri, 29 May 2009) | 1 line
complain if details are attached to a token
........
r73039 | benjamin.peterson | 2009-05-29 18:00:28 -0500 (Fri, 29 May 2009) | 1 line
add a test for whitespace
........
r73040 | benjamin.peterson | 2009-05-29 18:01:17 -0500 (Fri, 29 May 2009) | 1 line
a fix for emacs highlighting
........
r73091 | benjamin.peterson | 2009-05-31 20:55:25 -0500 (Sun, 31 May 2009) | 1 line
deprecate set_prefix() and get_prefix() in favor of a prefix property
........
r73092 | benjamin.peterson | 2009-05-31 21:00:51 -0500 (Sun, 31 May 2009) | 1 line
change hideous java naming scheme
........
r73093 | benjamin.peterson | 2009-05-31 21:01:39 -0500 (Sun, 31 May 2009) | 1 line
remove dated comment
........
r73096 | benjamin.peterson | 2009-05-31 21:40:53 -0500 (Sun, 31 May 2009) | 1 line
group tests
........
r73179 | benjamin.peterson | 2009-06-03 13:09:53 -0500 (Wed, 03 Jun 2009) | 1 line
handle the case where there's multiple trailers #6185
........
r73180 | benjamin.peterson | 2009-06-03 13:18:05 -0500 (Wed, 03 Jun 2009) | 1 line
scrap __main__ section
........
r73181 | benjamin.peterson | 2009-06-03 13:24:48 -0500 (Wed, 03 Jun 2009) | 1 line
remove shebang lines and __main__ sections
........
r73192 | benjamin.peterson | 2009-06-03 19:16:30 -0500 (Wed, 03 Jun 2009) | 4 lines
actually test something here
Thanks to Joe Amenta for noticing.y
........
r73231 | benjamin.peterson | 2009-06-04 13:38:50 -0500 (Thu, 04 Jun 2009) | 1 line
remove unused variable
........
r73244 | benjamin.peterson | 2009-06-05 08:39:25 -0500 (Fri, 05 Jun 2009) | 1 line
allow fixers to give different options in setUp
........
r73255 | benjamin.peterson | 2009-06-06 11:23:46 -0500 (Sat, 06 Jun 2009) | 1 line
fix the except fixer on one line suites #6222
........
r73256 | benjamin.peterson | 2009-06-06 11:27:40 -0500 (Sat, 06 Jun 2009) | 1 line
test one-line else and finally clauses
........
r73365 | benjamin.peterson | 2009-06-11 17:01:32 -0500 (Thu, 11 Jun 2009) | 1 line
normalize whitespace
........
2009-06-11 19:06:46 -03:00
|
|
|
meta_txt.prefix = u''
|
2008-09-13 14:43:19 -03:00
|
|
|
|
|
|
|
# compact the expression "metaclass = Meta" -> "metaclass=Meta"
|
|
|
|
expr_stmt = last_metaclass.children[0]
|
|
|
|
assert expr_stmt.type == syms.expr_stmt
|
Merged revisions 72523,72950-72951,72994,73003,73033,73036-73040,73091-73093,73096,73179-73181,73192,73231,73244,73255-73256,73365 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r72523 | benjamin.peterson | 2009-05-09 14:42:26 -0500 (Sat, 09 May 2009) | 1 line
remove parenthesis
........
r72950 | benjamin.peterson | 2009-05-26 18:19:45 -0500 (Tue, 26 May 2009) | 1 line
remove unused imports
........
r72951 | benjamin.peterson | 2009-05-26 18:27:00 -0500 (Tue, 26 May 2009) | 1 line
this is no longer executable
........
r72994 | benjamin.peterson | 2009-05-28 15:32:54 -0500 (Thu, 28 May 2009) | 1 line
fix test_all_fixers on Windows #6134
........
r73003 | benjamin.peterson | 2009-05-28 21:57:28 -0500 (Thu, 28 May 2009) | 4 lines
make 2to3 test utilities easier to use with other applications (3to2)
Patch by Joe Amenta
........
r73033 | benjamin.peterson | 2009-05-29 16:58:32 -0500 (Fri, 29 May 2009) | 1 line
update grammar for multi with statement
........
r73036 | benjamin.peterson | 2009-05-29 17:33:20 -0500 (Fri, 29 May 2009) | 1 line
simplify fix_unicode
........
r73037 | benjamin.peterson | 2009-05-29 17:53:03 -0500 (Fri, 29 May 2009) | 1 line
add custom error for pattern syntax errors
........
r73038 | benjamin.peterson | 2009-05-29 17:55:00 -0500 (Fri, 29 May 2009) | 1 line
complain if details are attached to a token
........
r73039 | benjamin.peterson | 2009-05-29 18:00:28 -0500 (Fri, 29 May 2009) | 1 line
add a test for whitespace
........
r73040 | benjamin.peterson | 2009-05-29 18:01:17 -0500 (Fri, 29 May 2009) | 1 line
a fix for emacs highlighting
........
r73091 | benjamin.peterson | 2009-05-31 20:55:25 -0500 (Sun, 31 May 2009) | 1 line
deprecate set_prefix() and get_prefix() in favor of a prefix property
........
r73092 | benjamin.peterson | 2009-05-31 21:00:51 -0500 (Sun, 31 May 2009) | 1 line
change hideous java naming scheme
........
r73093 | benjamin.peterson | 2009-05-31 21:01:39 -0500 (Sun, 31 May 2009) | 1 line
remove dated comment
........
r73096 | benjamin.peterson | 2009-05-31 21:40:53 -0500 (Sun, 31 May 2009) | 1 line
group tests
........
r73179 | benjamin.peterson | 2009-06-03 13:09:53 -0500 (Wed, 03 Jun 2009) | 1 line
handle the case where there's multiple trailers #6185
........
r73180 | benjamin.peterson | 2009-06-03 13:18:05 -0500 (Wed, 03 Jun 2009) | 1 line
scrap __main__ section
........
r73181 | benjamin.peterson | 2009-06-03 13:24:48 -0500 (Wed, 03 Jun 2009) | 1 line
remove shebang lines and __main__ sections
........
r73192 | benjamin.peterson | 2009-06-03 19:16:30 -0500 (Wed, 03 Jun 2009) | 4 lines
actually test something here
Thanks to Joe Amenta for noticing.y
........
r73231 | benjamin.peterson | 2009-06-04 13:38:50 -0500 (Thu, 04 Jun 2009) | 1 line
remove unused variable
........
r73244 | benjamin.peterson | 2009-06-05 08:39:25 -0500 (Fri, 05 Jun 2009) | 1 line
allow fixers to give different options in setUp
........
r73255 | benjamin.peterson | 2009-06-06 11:23:46 -0500 (Sat, 06 Jun 2009) | 1 line
fix the except fixer on one line suites #6222
........
r73256 | benjamin.peterson | 2009-06-06 11:27:40 -0500 (Sat, 06 Jun 2009) | 1 line
test one-line else and finally clauses
........
r73365 | benjamin.peterson | 2009-06-11 17:01:32 -0500 (Thu, 11 Jun 2009) | 1 line
normalize whitespace
........
2009-06-11 19:06:46 -03:00
|
|
|
expr_stmt.children[1].prefix = u''
|
|
|
|
expr_stmt.children[2].prefix = u''
|
2008-09-13 14:43:19 -03:00
|
|
|
|
|
|
|
arglist.append_child(last_metaclass)
|
|
|
|
|
|
|
|
fixup_indent(suite)
|
|
|
|
|
|
|
|
# check for empty suite
|
|
|
|
if not suite.children:
|
|
|
|
# one-liner that was just __metaclass_
|
|
|
|
suite.remove()
|
2009-05-08 22:01:14 -03:00
|
|
|
pass_leaf = Leaf(text_type, u'pass')
|
Merged revisions 72523,72950-72951,72994,73003,73033,73036-73040,73091-73093,73096,73179-73181,73192,73231,73244,73255-73256,73365 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r72523 | benjamin.peterson | 2009-05-09 14:42:26 -0500 (Sat, 09 May 2009) | 1 line
remove parenthesis
........
r72950 | benjamin.peterson | 2009-05-26 18:19:45 -0500 (Tue, 26 May 2009) | 1 line
remove unused imports
........
r72951 | benjamin.peterson | 2009-05-26 18:27:00 -0500 (Tue, 26 May 2009) | 1 line
this is no longer executable
........
r72994 | benjamin.peterson | 2009-05-28 15:32:54 -0500 (Thu, 28 May 2009) | 1 line
fix test_all_fixers on Windows #6134
........
r73003 | benjamin.peterson | 2009-05-28 21:57:28 -0500 (Thu, 28 May 2009) | 4 lines
make 2to3 test utilities easier to use with other applications (3to2)
Patch by Joe Amenta
........
r73033 | benjamin.peterson | 2009-05-29 16:58:32 -0500 (Fri, 29 May 2009) | 1 line
update grammar for multi with statement
........
r73036 | benjamin.peterson | 2009-05-29 17:33:20 -0500 (Fri, 29 May 2009) | 1 line
simplify fix_unicode
........
r73037 | benjamin.peterson | 2009-05-29 17:53:03 -0500 (Fri, 29 May 2009) | 1 line
add custom error for pattern syntax errors
........
r73038 | benjamin.peterson | 2009-05-29 17:55:00 -0500 (Fri, 29 May 2009) | 1 line
complain if details are attached to a token
........
r73039 | benjamin.peterson | 2009-05-29 18:00:28 -0500 (Fri, 29 May 2009) | 1 line
add a test for whitespace
........
r73040 | benjamin.peterson | 2009-05-29 18:01:17 -0500 (Fri, 29 May 2009) | 1 line
a fix for emacs highlighting
........
r73091 | benjamin.peterson | 2009-05-31 20:55:25 -0500 (Sun, 31 May 2009) | 1 line
deprecate set_prefix() and get_prefix() in favor of a prefix property
........
r73092 | benjamin.peterson | 2009-05-31 21:00:51 -0500 (Sun, 31 May 2009) | 1 line
change hideous java naming scheme
........
r73093 | benjamin.peterson | 2009-05-31 21:01:39 -0500 (Sun, 31 May 2009) | 1 line
remove dated comment
........
r73096 | benjamin.peterson | 2009-05-31 21:40:53 -0500 (Sun, 31 May 2009) | 1 line
group tests
........
r73179 | benjamin.peterson | 2009-06-03 13:09:53 -0500 (Wed, 03 Jun 2009) | 1 line
handle the case where there's multiple trailers #6185
........
r73180 | benjamin.peterson | 2009-06-03 13:18:05 -0500 (Wed, 03 Jun 2009) | 1 line
scrap __main__ section
........
r73181 | benjamin.peterson | 2009-06-03 13:24:48 -0500 (Wed, 03 Jun 2009) | 1 line
remove shebang lines and __main__ sections
........
r73192 | benjamin.peterson | 2009-06-03 19:16:30 -0500 (Wed, 03 Jun 2009) | 4 lines
actually test something here
Thanks to Joe Amenta for noticing.y
........
r73231 | benjamin.peterson | 2009-06-04 13:38:50 -0500 (Thu, 04 Jun 2009) | 1 line
remove unused variable
........
r73244 | benjamin.peterson | 2009-06-05 08:39:25 -0500 (Fri, 05 Jun 2009) | 1 line
allow fixers to give different options in setUp
........
r73255 | benjamin.peterson | 2009-06-06 11:23:46 -0500 (Sat, 06 Jun 2009) | 1 line
fix the except fixer on one line suites #6222
........
r73256 | benjamin.peterson | 2009-06-06 11:27:40 -0500 (Sat, 06 Jun 2009) | 1 line
test one-line else and finally clauses
........
r73365 | benjamin.peterson | 2009-06-11 17:01:32 -0500 (Thu, 11 Jun 2009) | 1 line
normalize whitespace
........
2009-06-11 19:06:46 -03:00
|
|
|
pass_leaf.prefix = orig_meta_prefix
|
2008-09-13 14:43:19 -03:00
|
|
|
node.append_child(pass_leaf)
|
2009-05-08 22:01:14 -03:00
|
|
|
node.append_child(Leaf(token.NEWLINE, u'\n'))
|
2008-09-13 14:43:19 -03:00
|
|
|
|
|
|
|
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__
|
2009-05-08 22:01:14 -03:00
|
|
|
pass_leaf = Leaf(text_type, u'pass')
|
2008-09-13 14:43:19 -03:00
|
|
|
suite.insert_child(-1, pass_leaf)
|
2009-05-08 22:01:14 -03:00
|
|
|
suite.insert_child(-1, Leaf(token.NEWLINE, u'\n'))
|