Skip to content

Commit

Permalink
Replace 'counter' function with 'collection.Counter'
Browse files Browse the repository at this point in the history
Closes #813
  • Loading branch information
edreamleo authored Jun 28, 2024
1 parent c68ed1b commit ac563ed
Showing 1 changed file with 2 additions and 13 deletions.
15 changes: 2 additions & 13 deletions pyflakes/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,17 +165,6 @@ def __missing__(self, node_class):
return fields


def counter(items):
"""
Simplest required implementation of collections.Counter. Required as 2.6
does not have Counter in collections.
"""
results = {}
for item in items:
results[item] = results.get(item, 0) + 1
return results


def iter_child_nodes(node, omit=None, _fields_order=_FieldsOrder()):
"""
Yield all direct child nodes of *node*, that is, all fields that
Expand Down Expand Up @@ -1777,7 +1766,7 @@ def DICT(self, node):
convert_to_value(key) for key in node.keys
]

key_counts = counter(keys)
key_counts = collections.Counter(keys)
duplicate_keys = [
key for key, count in key_counts.items()
if count > 1
Expand All @@ -1786,7 +1775,7 @@ def DICT(self, node):
for key in duplicate_keys:
key_indices = [i for i, i_key in enumerate(keys) if i_key == key]

values = counter(
values = collections.Counter(
convert_to_value(node.values[index])
for index in key_indices
)
Expand Down

0 comments on commit ac563ed

Please sign in to comment.