mirror of
https://github.com/python/cpython.git
synced 2025-11-03 03:22:27 +00:00
Do the same thing to complex that I did to str: the rich comparison
function returns NotImplemented when comparing objects whose tp_richcompare slot is not itself.
This commit is contained in:
parent
e47df7a211
commit
2205642fe0
2 changed files with 25 additions and 7 deletions
|
|
@ -1863,6 +1863,21 @@ def classic_comparisons():
|
|||
def rich_comparisons():
|
||||
if verbose:
|
||||
print "Testing rich comparisons..."
|
||||
class Z(complex):
|
||||
pass
|
||||
z = Z(1)
|
||||
verify(z == 1+0j)
|
||||
verify(1+0j == z)
|
||||
class ZZ(complex):
|
||||
def __eq__(self, other):
|
||||
try:
|
||||
return abs(self - other) <= 1e-6
|
||||
except:
|
||||
return NotImplemented
|
||||
zz = ZZ(1.0000003)
|
||||
verify(zz == 1+0j)
|
||||
verify(1+0j == zz)
|
||||
|
||||
class classic:
|
||||
pass
|
||||
for base in (classic, int, object, list):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue