Steven D'Aprano wrote:
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}
Every set is a superset of itself and a subset of itself. A set may not be a "formal" subset or a "formal" superset of itself. `issubset` and `issuperset` refer to standard subsets and supersets, not formal subsets and supersets.
In Python, you can trivially check that… ``` In [1]: {1, 2, 3}.issubset({1, 2, 3}) Out[1]: True
In [2]: {1, 2, 3}.issuperset({1, 2, 3}) Out[2]: True
In [3]: {1, 2, 3}.issubset((1, 2, 3)) Out[3]: True
In [4]: {1, 2, 3}.issuperset((1, 2, 3)) Out[4]: True ```