Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1aeba74

Browse files
Windsooonmiss-islington
authored andcommitted
bpo-34552: Clarify built-in types comparisons (GH-9035)
Some updates to ancient text about comparisons; fixes bp-34552.
1 parent 1401018 commit 1aeba74

2 files changed

Lines changed: 10 additions & 10 deletions

File tree

Doc/library/stdtypes.rst

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ rearrange their members in place, and don't return a specific item, never return
2020
the collection instance itself but ``None``.
2121

2222
Some operations are supported by several object types; in particular,
23-
practically all objects can be compared, tested for truth value, and converted
24-
to a string (with the :func:`repr` function or the slightly different
25-
:func:`str` function). The latter function is implicitly used when an object is
26-
written by the :func:`print` function.
23+
practically all objects can be compared for equality, tested for truth
24+
value, and converted to a string (with the :func:`repr` function or the
25+
slightly different :func:`str` function). The latter function is implicitly
26+
used when an object is written by the :func:`print` function.
2727

2828

2929
.. _truth:
@@ -164,12 +164,10 @@ This table summarizes the comparison operations:
164164
pair: objects; comparing
165165

166166
Objects of different types, except different numeric types, never compare equal.
167-
Furthermore, some types (for example, function objects) support only a degenerate
168-
notion of comparison where any two objects of that type are unequal. The ``<``,
169-
``<=``, ``>`` and ``>=`` operators will raise a :exc:`TypeError` exception when
170-
comparing a complex number with another built-in numeric type, when the objects
171-
are of different types that cannot be compared, or in other cases where there is
172-
no defined ordering.
167+
The ``==`` operator is always defined but for some object types (for example,
168+
class objects) is equivalent to :keyword:`is`. The ``<``, ``<=``, ``>`` and ``>=``
169+
operators are only defined where they make sense; for example, they raise a
170+
:exc:`TypeError` exception when one of the arguments is a complex number.
173171

174172
.. index::
175173
single: __eq__() (instance method)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Make clear that ``==`` operator sometimes is equivalent to `is`. The ``<``,
2+
``<=``, ``>`` and ``>=`` operators are only defined where they make sense.

0 commit comments

Comments
 (0)