cpython icon indicating copy to clipboard operation
cpython copied to clipboard

Rephrase general rules for comparison of objects

Open skirpichev opened this issue 2 months ago • 2 comments

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

skirpichev avatar Nov 08 '25 00:11 skirpichev

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

Yashp002 avatar Nov 15 '25 16:11 Yashp002

A PR already exists so there is nothing else to do.

picnixz avatar Nov 15 '25 17:11 picnixz