#python - Wed 16 May 2007 between 09:02 and 09:08



Yhg1stazle: that is not the right sense.
tazle: the 'is-sense' is senseless.
tazleYhg1s: for dicts it's not
Yhg1stazle: yes.
tazle: equality is quite well-defined, in Python. By the equality operator. ==. That's it.
dicts don't care about 'is', only about '=='.
so they cannot be 'equal but different'.
AStormExactly.
tazleYhg1s: however, dictionaries also care for hash
qebabhrm, would you be able to use the id() as a key?
AStormIf __eq__ is not defined
then the default object uses id()
for ==
Yhg1stazle: yes. however, objects who compare equal to each other *must* also have hashes that compare equal, or they are plain broken. That doesn't mean they're 'equal but different', it just means they're kaput.
tazleYhg1s: which is what I mean by "erro on your part" in my original comment
Yhg1stazle: I didn't object to the 'error on your part' part, I objected to the 'they can' part :)
it's an error, but they're still not equal-but-different :)
qebab: have an object only compare equal to itself.
wilx|wrkWell, we are back to my original question. Sort of.
Yhg1sqebab: which is the default behaviour if you have neither __eq__ or __hash__ defined.
wilx|wrkDoes my example's x and y make two distinct keys?
tazleYhg1s: for a given value of different :)
wilx|wrkAssuming Foo is plain class Foo(object): some fields, no methods.
Yhg1stazle: 'different' is the opposite of 'equal'. again, well-defined in Python.
tazleYhg1s: oh? where?
Yhg1swilx|wrk: what matters is the __eq__ method. if it has no __eq__ method, two different instances are by definition different -- it doesn't matter that they have the same contents.
wilx|wrk: if they do have an __eq__ method, they are equal if the __eq__ method says they are.
tazle: where was? Where is '==' defined as the equality operator? In the language reference. where is 'different' defined as 'not equal'? Nowhere explicitly, I believe, although it may be obliquely mentioned in the language ref. that doesn't mean it isn't so though :)
tazle: everything in Python assumes this common-sense relation.
AStorm!= is defined as not equal
wilx|wrkSo, ok, so, objet's __eq__ compares id()s by default then?
AStormthere's no definition of "different" :>
wilx|wrk, not really
Yhg1swilx|wrk: more or less, yes.
AStormif there's no __eq__, then there's no __eq__
but the == operator will use id()
Yhg1sobject.__eq__ always exists, though.
AStormHm?
Yhg1soh, hm, it does not.
AStormLet me check...

Page: 3 10 17 24 31 38 45 52 59 66 73 80 87 

IrcArchive