Skip to content

Commit 508d8cd

Browse files
committed
Merge pull request #65 from brettcannon/simplify_fix_metaclass
Simplify fix_metaclass
2 parents 7f6e921 + 17a464d commit 508d8cd

File tree

2 files changed

+5
-22
lines changed

2 files changed

+5
-22
lines changed

libmodernize/fixes/fix_metaclass.py

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -209,27 +209,9 @@ def transform(self, node, results):
209209
arguments = [metaclass]
210210

211211
if arglist.children:
212-
if len(arglist.children) == 1:
213-
base = arglist.children[0].clone()
214-
base.prefix = u' '
215-
else:
216-
# Unfortunately six.with_metaclass() only allows one base
217-
# class, so we have to dynamically generate a base class if
218-
# there is more than one.
219-
bases = parenthesize(arglist.clone())
220-
bases.prefix = u' '
221-
base = Call(Name('type'), [
222-
String("'NewBase'"),
223-
Comma(),
224-
bases,
225-
Comma(),
226-
Node(
227-
syms.atom,
228-
[Leaf(token.LBRACE, u'{'), Leaf(token.RBRACE, u'}')],
229-
prefix=u' '
230-
)
231-
], prefix=u' ')
232-
arguments.extend([Comma(), base])
212+
bases = arglist.clone()
213+
bases.prefix = u' '
214+
arguments.extend([Comma(), bases])
233215

234216
arglist.replace(Call(
235217
Name(u'six.with_metaclass', prefix=arglist.prefix),

tests/test_fix_metaclass.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class Foo(Bar, Spam):
3333
__metaclass__ = Meta
3434
""", """\
3535
import six
36-
class Foo(six.with_metaclass(Meta, type('NewBase', (Bar, Spam), {}))):
36+
class Foo(six.with_metaclass(Meta, Bar, Spam)):
3737
pass
3838
""")
3939

@@ -56,6 +56,7 @@ class Foo(six.with_metaclass(Meta, Bar)):
5656
"""
5757
)
5858

59+
5960
def test_metaclass_no_base():
6061
check_on_input(*METACLASS_NO_BASE)
6162

0 commit comments

Comments
 (0)