[Python-checkins] r67371 - in sandbox/trunk/2to3/lib2to3: fixes/fix_metaclass.py tests/test_fixers.py
benjamin.peterson
python-checkins at python.org
Mon Nov 24 23:02:00 CET 2008
Author: benjamin.peterson
Date: Mon Nov 24 23:02:00 2008
New Revision: 67371
Log:
don't blow up in the metaclass fixer when assignments in the class statement aren't simple
Modified:
sandbox/trunk/2to3/lib2to3/fixes/fix_metaclass.py
sandbox/trunk/2to3/lib2to3/tests/test_fixers.py
Modified: sandbox/trunk/2to3/lib2to3/fixes/fix_metaclass.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/fixes/fix_metaclass.py (original)
+++ sandbox/trunk/2to3/lib2to3/fixes/fix_metaclass.py Mon Nov 24 23:02:00 2008
@@ -110,8 +110,11 @@
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:
- leaf_node = expr_node.children[0]
- if leaf_node.value == '__metaclass__':
+ # 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__':
+ # We found a assignment to __metaclass__.
fixup_simple_stmt(node, i, simple_node)
remove_trailing_newline(simple_node)
yield (node, i, simple_node)
Modified: sandbox/trunk/2to3/lib2to3/tests/test_fixers.py
==============================================================================
--- sandbox/trunk/2to3/lib2to3/tests/test_fixers.py (original)
+++ sandbox/trunk/2to3/lib2to3/tests/test_fixers.py Mon Nov 24 23:02:00 2008
@@ -3769,6 +3769,17 @@
"""
self.check(b, a)
+ b = """
+ class X:
+ __metaclass__ = Meta
+ save.py = 23
+ """
+ a = """
+ class X(metaclass=Meta):
+ save.py = 23
+ """
+ self.check(b, a)
+
class Test_getcwdu(FixerTestCase):
More information about the Python-checkins
mailing list