-
-
Notifications
You must be signed in to change notification settings - Fork 33.9k
Closed
Labels
testsTests in the Lib/test dirTests in the Lib/test dirtype-featureA feature request or enhancementA feature request or enhancement
Description
Feature or enhancement
Proposal:
I was trying to find optimizations in collections.Counter comparison operations, and found something that passed existing unit tests:
@@ -814,7 +814,7 @@ def __le__(self, other):
'True if all counts in self are a subset of those in other.'
if not isinstance(other, Counter):
return NotImplemented
- return all(self[e] <= other[e] for c in (self, other) for e in c)
+ return all(self[e] <= other[e] for e in self)
def __lt__(self, other):
'True if all counts in self are a proper subset of those in other.'
@@ -826,7 +826,7 @@ def __ge__(self, other):
'True if all counts in self are a superset of those in other.'
if not isinstance(other, Counter):
return NotImplemented
- return all(self[e] >= other[e] for c in (self, other) for e in c)
+ return all(self[e] >= other[e] for e in other)
def __gt__(self, other):
'True if all counts in self are a proper superset of those in other.'However, this breaks the semantics of the class, because documentation says that missing keys are handled as if they had count 0.
I will make a PR to add more tests to catch this case.
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response
Linked PRs
Metadata
Metadata
Assignees
Labels
testsTests in the Lib/test dirTests in the Lib/test dirtype-featureA feature request or enhancementA feature request or enhancement