[Python-Dev] == on object tests identity in 3.x (original) (raw)
[Python-Dev] == on object tests identity in 3.x - list delegation to members?
Ethan Furman ethan at stoneleaf.us
Mon Jul 14 04:55:37 CEST 2014
- Previous message: [Python-Dev] == on object tests identity in 3.x - list delegation to members?
- Next message: [Python-Dev] == on object tests identity in 3.x - list delegation to members?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Previous message: [Python-Dev] == on object tests identity in 3.x - list delegation to members?
- Next message: [Python-Dev] == on object tests identity in 3.x - list delegation to members?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]