Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace 'counter' function with 'collection.Counter' #814

Merged
merged 4 commits into from
Jun 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading