Skip to content

Commit

Permalink
Sort line numbers of duplicates
Browse files Browse the repository at this point in the history
The logic of `get_occurrence_in_object()` previously assumed the input
line numbers were sorted.

This fixes #29.
  • Loading branch information
myint committed Jan 12, 2018
1 parent 2afe86f commit 265e608
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion autoflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ def get_occurrence_in_object(line, line_number, key, marked_line_numbers,
closing_object_lines[i] >= line_number][0]

obj_lines = []
for ln in marked_line_numbers:
for ln in sorted(marked_line_numbers):
if (
opening_object_lines[obj] <= ln and
closing_object_lines[obj] >= ln and
Expand Down
24 changes: 24 additions & 0 deletions test_autoflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,30 @@ def test_filter_code_with_duplicate_key(self):
(0,1): 3,
}
print(a)
""", remove_duplicate_keys=True)))

def test_filter_code_with_duplicate_key_longer(self):
self.assertEqual(
"""\
{
'a': 0,
'c': 2,
'd': 3,
'e': 4,
'f': 5,
'b': 6,
}
""",
''.join(autoflake.filter_code("""\
{
'a': 0,
'b': 1,
'c': 2,
'd': 3,
'e': 4,
'f': 5,
'b': 6,
}
""", remove_duplicate_keys=True)))

def test_filter_code_with_special_re_symbols_in_key(self):
Expand Down

0 comments on commit 265e608

Please sign in to comment.