Kaydet (Commit) 4261a3e4 authored tarafından Anthony Sottile's avatar Anthony Sottile

Fix extra comma in tuples which contain a fix in their first element

üst 47e21e15
......@@ -347,16 +347,18 @@ def _fix_src(contents_text, py35_plus, py36_plus):
elif key in visitor.literals:
fixes.append((True, _find_simple(i, tokens)))
# need to additionally handle literals afterwards as tuples report
# their starting index as the first element, which may be one of the
# above things.
if key in visitor.tuples:
fixes.append((True, _find_tuple(i, tokens)))
for add_comma, fix_data in fixes:
if fix_data is not None:
_fix_brace(fix_data, add_comma, tokens)
# need to handle tuples afterwards as tuples report their starting
# starting index as the first element, which may be one of the above
# things.
if key in visitor.tuples:
fix_data = _find_tuple(i, tokens)
if fix_data is not None:
_fix_brace(fix_data, True, tokens)
return tokens_to_src(tokens)
......
......@@ -565,6 +565,18 @@ def test_noop_unhugs(src):
' "bar",\n'
')',
),
# Regression test for #29
(
'x = ([a,\n'
' b], None)',
'x = (\n'
' [\n'
' a,\n'
' b,\n'
' ], None,\n'
')',
),
),
)
def test_fix_unhugs(src, expected):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment