This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author steven.daprano Saimadhav.Heblikar, cool-RR, eric.smith, ethan.furman, josh.r, mark.dickinson, pitrou, r.david.murray, rhettinger, scoder, serhiy.storchaka, steven.daprano 2014-10-04.15:24:22 -1.0 Yes <20141004152330.GL19757@ando.pearwood.info> <1412419382.66.0.140232493817.issue22515@psf.upfronthosting.co.za>
Content
```On Sat, Oct 04, 2014 at 10:43:02AM +0000, Antoine Pitrou wrote:

> Just because something is discussed doesn't mean it needs a PEP.

I know that in general discussions do not need a PEP, but we seem to be
rushing awfully fast into writing code before we even know what the code
is supposed to do. Perhaps "need a PEP" was too strong, but we surely
need to do something to decide on constistent and well-defined
behaviour. As you pointed out earlier, Counters aren't precisely
multisets, they're more like a hybrid mapping/multiset. It's not clear
what behaviour subset and superset should have for such a hybrid. By
rushing into code before deciding on what the code is supposed to do, we
end up with inconsistent behaviour.

Here are a pair of Counters which compare "is subset", but not "is
subset or equal" using Ram's patch:

py> Counter(a=1, b=0) < Counter(a=2)
True
py> Counter(a=1, b=0) <= Counter(a=2)
False

On the other hand, here's a pair which compares "is subset or equal",
but not ("is subset" or "equal"):

py> Counter(a=0) <= Counter(b=0)
True
py> (Counter(a=0) < Counter(b=0)) or (Counter(a=0) == Counter(b=0))
False

Adding elements with count=0 changes whether a set is a subset or not:

py> Counter(a=0) < Counter(b=0)
False
py> Counter(a=0) < Counter(b=0, c=0)
True
py> Counter(a=0, b=0) < Counter(b=0, c=0)
False

I'm not convinced that mixed Counter and regular dict comparisons should
be supported, but Ram's patch supports any Mapping type. Is that a good
idea? There's been no discussion on that question.

Can somebody explain to me what this means? How is this meaningfully a
subset operation?

py> Counter(a="eggs") < Counter(a="spam")
True

I supported adding these operations to Counter, but the last thing I
want is to enshrine a set of ad-hoc and inconsistent semantics that
don't match standard multiset behaviour and are defined by the
implementation, instead of having the implementation defined by the
desired semantics.```
History
Date User Action Args
2014-10-04 15:24:23steven.dapranosetrecipients: + steven.daprano, rhettinger, mark.dickinson, pitrou, scoder, eric.smith, r.david.murray, cool-RR, ethan.furman, serhiy.storchaka, Saimadhav.Heblikar, josh.r