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

Skip to content

Commit a88479f

Browse files
committed
- Add note about complex numbers.
- Changed description of rich comparisons to emphasize that < and > (etc.) are each other's reflection. Also use this word in the note about the demise of __rcmp__.
1 parent 9483bed commit a88479f

1 file changed

Lines changed: 16 additions & 9 deletions

File tree

Misc/NEWS

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,32 @@ Core language, builtins, and interpreter
2929

3030
Classes can overload individual comparison operators by defining one
3131
or more of the methods__lt__, __le__, __eq__, __ne__, __gt__,
32-
__ge__. There are no explicit "reversed argument" versions of
33-
these; instead, __lt__ and __gt__ are each other's reverse, likewise
34-
for__le__ and __ge__; __eq__ and __ne__ are their own reverse
35-
(similar at the C level). No other implications are made; in
36-
particular, Python does not assume that == is the inverse of !=, or
37-
that < is the inverse of >=. This makes it possible to define types
38-
with partial orderings.
32+
__ge__. There are no explicit "reflected argument" versions of
33+
these; instead, __lt__ and __gt__ are each other's reflection,
34+
likewise for__le__ and __ge__; __eq__ and __ne__ are their own
35+
reflection (similar at the C level). No other implications are
36+
made; in particular, Python does not assume that == is the Boolean
37+
inverse of !=, or that < is the Boolean inverse of >=. This makes
38+
it possible to define types with partial orderings.
3939

4040
Classes or types that want to implement (in)equality tests but not
4141
the ordering operators (i.e. unordered types) should implement ==
4242
and !=, and raise an error for the ordering operators.
4343

44-
It is possible to define types whose comparison results are not
44+
It is possible to define types whose rich comparison results are not
4545
Boolean; e.g. a matrix type might want to return a matrix of bits
4646
for A < B, giving elementwise comparisons. Such types should ensure
4747
that any interpretation of their value in a Boolean context raises
4848
an exception, e.g. by defining __nonzero__ (or the tp_nonzero slot
4949
at the C level) to always raise an exception.
5050

51+
- Complex numbers use rich comparisons to define == and != but raise
52+
an exception for <, <=, > and >=. Unfortunately, this also means
53+
that cmp() of two complex numbers raises an exception when the two
54+
numbers differ. Since it is not mathematically meaningful to compare
55+
complex numbers except for equality, I hope that this doesn't break
56+
too much code.
57+
5158
- Functions and methods now support getting and setting arbitrarily
5259
named attributes (PEP 232). Functions have a new __dict__
5360
(a.k.a. func_dict) which hold the function attributes. Methods get
@@ -113,7 +120,7 @@ Core language, builtins, and interpreter
113120
subtly. Since this was a terrible gray area of the language, this
114121
is considered an improvement. Also note that __rcmp__ is no longer
115122
supported -- instead of calling __rcmp__, __cmp__ is called with
116-
reversed arguments.
123+
reflected arguments.
117124

118125
- In connection with the coercion changes, a new built-in singleton
119126
object, NotImplemented is defined. This can be returned for

0 commit comments

Comments
 (0)