On 07/13/2014 08:13 AM, Andreas Maier wrote:
Am 11.07.2014 22:54, schrieb Ethan Furman:
Here is the externally visible behavior:
Python 3.5.0a0 (default:34881ee3eec5, Jun 16 2014, 11:31:20)
[GCC 4.7.3] on linux
Type "help", "copyright", "credits" or "license" for more information.
--> NaN = float('nan')
--> NaN == NaN
False
--> [NaN] == [NaN]
True
Ouch, that hurts ;-)
Yeah, I've been bitten enough times that now I try to always test code before I
post. ;)
Test #8: Same object of class C
(C.__eq__() implemented with equality of x,
C.__ne__() returning NotImplemented):
obj1: type=<class '__main__.C'>, str=C(256), id=39406504
obj2: type=<class '__main__.C'>, str=C(256), id=39406504
a) obj1 is obj2: True
C.__eq__(): self=39406504, other=39406504, returning True
This is interesting/weird/odd -- why is __eq__ being called for an 'is' test?
--- test_eq.py ----------------------------
class TestEqTrue:
def __eq__(self, other):
print('Test.__eq__ returning True')
return True
class TestEqFalse:
def __eq__(self, other):
print('Test.__eq__ returning False')
return False
tet = TestEqTrue()
print(tet is tet)
print(tet in [tet])
tef = TestEqFalse()
print(tef is tef)
print(tef in [tef])
-------------------------------------------
When I run this all I get is four Trues, never any messages about being in
__eq__.
How did you get that result?
--
~Ethan~
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com