Rephrase general rules for comparison of objects
Right now we have this in docs:
Objects of different types, except different numeric types, never compare equal.
This is not true for a long time, e.g. frozenset's vs set's - another exception:
Python 3.14.0 (tags/v3.14.0:ebf955df7a8, Oct 15 2025, 06:24:48) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> frozenset([1, 2]) == {1, 2}
True
In the relevant place of docs its documented:
Both set and frozenset support set to set comparisons. Two sets are equal if and only if every element of each set is contained in the other (each is a subset of the other). A set is less than another set if and only if the first set is a proper subset of the second set (is a subset, but is not equal). A set is greater than another set if and only if the first set is a proper superset of the second set (is a superset, but is not equal).
Instances of set are compared to instances of frozenset based on their members.
but we should adjust also the generic texts, something like:
Objects of different types, unless documented otherwise, never compare equal.
PS: https://discuss.python.org/t/104658/
Linked PRs
- gh-141221
- gh-142810
- gh-142811
Hi! I’d like to take this. Plan:
Update the generic comparison rule in Doc/library/stdtypes.rst to: ‘Objects of different types, unless documented otherwise, never compare equal.’
Add a short note that some types explicitly define cross-type equality.
Insert a cross-reference to the sets documentation where set/frozenset comparison semantics are described. I’ll build the docs locally and ensure no new Sphinx warnings. ETA: 1–2 days
A PR already exists so there is nothing else to do.