On Sun, Mar 22, 2020 at 07:59:59PM -0000, Steve Jorgensen wrote: > Currently, the `issubset` and `issuperset` methods of set objects > accept arbitrary iterables as arguments. An iterable that is both a > subset and superset is, in a sense, "equal" to the set. It would be > inappropriate for `==` to return `True` for such a comparison, > however, since that would break the `Hashable` contract.
I think the "arbitrary iterables" part is a distraction. We are fundamentally talking about a comparison on sets, even if Python relaxes the requirements and also allows one operand to be a arbitrary iterable. I don't believe that a set A can be both a superset and subset of another set B at the same time. On a Venn Diagram, that would require A to be both completely surrounded by B and B to be completely surrounded by A at the same time, which is impossible. I think you might be talking about sets which partially overlap: A = {1, 2, 3, 4} B = {2, 3, 4, 5} but neither the issubset nor issuperset methods return True in that case: * A is not a subset of B because 1 is not in B; * A is not a superset of B because it lacks 5; * B is not a subset of A because 5 is not in A; * and B is not a superset of A because it lacks 1. You are right that it would be inappropriate to return equal, but nothing to do with Hashable since sets aren't hashable. They are not equal because, well, they ain't equal :-) > Should sets have an additional method, something like `like(other)`, > `issimilar(other)`, or `isequivalent(other)`, that returns `True` for > any iterable that contains the all of the items in the set and no > items that are not in the set? That would be equality :-) A = {1, 2, 3, 4} B = {1, 2, 3, 4} B contains all of the items in A and no items which are not in A; likewise A contains all the items in B and no items not in B. That makes them equal. I might be missing something obvious, but I really don't think that `<set>.issubset(other) and <set>.issuperset(other)` can be true. -- Steven _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/N3RURYO323Z2GLJNSURD52HUVW6PIJOH/ Code of Conduct: http://python.org/psf/codeofconduct/