Skip to content

Commit

Permalink
Only look at relevant messages
Browse files Browse the repository at this point in the history
  • Loading branch information
myint committed Jan 4, 2018
1 parent a61bfc3 commit 347f8fe
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
6 changes: 6 additions & 0 deletions autoflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,10 @@ def any_complex_duplicate_key_cases(messages, source):
"""
lines = source.split('\n')
for message in messages:
if not isinstance(message,
pyflakes.messages.MultiValueRepeatedKeyLiteral):
continue

line = lines[message.lineno - 1]
key = message.message_args[0]

Expand All @@ -399,6 +403,8 @@ def any_complex_duplicate_key_cases(messages, source):
):
return True

return False


def get_messages_by_line(messages):
"""Return dictionary that maps line number to message."""
Expand Down
38 changes: 38 additions & 0 deletions test_autoflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -1420,6 +1420,44 @@ def test_end_to_end_with_remove_duplicate_keys_multiple_lines(self):
- 'b': 7834,
'a': 'wow',
- 'b': 456,
- 'c': 'hello',
'c': 'hello2',
- 'b': 'hiya',
"b": 'hiya',
}
print(a)
""", '\n'.join(process.communicate()[0].decode().split('\n')[3:]))

def test_end_to_end_with_remove_duplicate_keys_and_other_errors(self):
with temporary_file("""\
from math import *
print(sin(4))
a = { # Hello
'b': 456,
'a': 123,
'b': 7834,
'a': 'wow',
'b': 456,
'c': 'hello',
'c': 'hello2',
'b': 'hiya',
"b": 'hiya',
}
print(a)
""") as filename:
process = subprocess.Popen(AUTOFLAKE_COMMAND +
['--remove-duplicate-keys',
filename],
stdout=subprocess.PIPE)
self.assertEqual("""\
from math import *
print(sin(4))
a = { # Hello
- 'b': 456,
- 'a': 123,
- 'b': 7834,
'a': 'wow',
- 'b': 456,
- 'c': 'hello',
'c': 'hello2',
- 'b': 'hiya',
Expand Down

0 comments on commit 347f8fe

Please sign in to comment.