Commits

Steven Silvester  committed b9455c6

Imporved newstyle fix: make sure it inherits from 'object'

  • Participants
  • Parent commits df09a22

Comments (0)

Files changed (2)

File lib3to2/fixes/fix_newstyle.py

     node.insert_child(idx, Name("object"))
     node.insert_child(idx, LParen())
 
+
 class FixNewstyle(fixer_base.BaseFix):
 
-    PATTERN = "classdef< 'class' NAME colon=':' any >"
+    PATTERN = u"classdef< 'class' NAME [paren='('] [')'] colon=':' any >"
 
     def transform(self, node, results):
-        colon = results["colon"]
-        idx = node.children.index(colon)
-        insert_object(node, idx)
+        if 'paren' in results:
+            paren = results[u'paren']
+            idx = node.children.index(paren)
+            node.insert_child(idx + 1, Name(u"object"))
+        else:
+            colon = results[u'colon']
+            idx = node.children.index(colon)
+            insert_object(node, idx)
+        

File lib3to2/tests/test_newstyle.py

 from lib3to2.tests.support import lib3to2FixerTestCase
 
 class Test_newstyle(lib3to2FixerTestCase):
-    fixer = "newstyle"
+    fixer = u"newstyle"
 
     def test_oneline(self):
 
-        b = """class Foo: pass"""
-        a = """class Foo(object): pass"""
+        b = u"""class Foo: pass"""
+        a = u"""class Foo(object): pass"""
         self.check(b, a)
 
     def test_suite(self):
 
-        b = """
-        class Foo:
+        b = u"""
+        class Foo():
             do_stuff()"""
-        a = """
+        a = u"""
         class Foo(object):
             do_stuff()"""
         self.check(b, a)
+