| Yhg1s | tazle: that is not the right sense. tazle: the 'is-sense' is senseless. |
| tazle | Yhg1s: for dicts it's not |
| Yhg1s | tazle: 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'. |
| AStorm | Exactly. |
| tazle | Yhg1s: however, dictionaries also care for hash |
| qebab | hrm, would you be able to use the id() as a key? |
| AStorm | If __eq__ is not defined then the default object uses id() for == |
| Yhg1s | tazle: 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. |
| tazle | Yhg1s: which is what I mean by "erro on your part" in my original comment |
| Yhg1s | tazle: 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|wrk | Well, we are back to my original question. Sort of. |
| Yhg1s | qebab: which is the default behaviour if you have neither __eq__ or __hash__ defined. |
| wilx|wrk | Does my example's x and y make two distinct keys? |
| tazle | Yhg1s: for a given value of different :) |
| wilx|wrk | Assuming Foo is plain class Foo(object): some fields, no methods. |
| Yhg1s | tazle: 'different' is the opposite of 'equal'. again, well-defined in Python. |
| tazle | Yhg1s: oh? where? |
| Yhg1s | wilx|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|wrk | So, ok, so, objet's __eq__ compares id()s by default then? |
| AStorm | there's no definition of "different" :> wilx|wrk, not really |
| Yhg1s | wilx|wrk: more or less, yes. |
| AStorm | if there's no __eq__, then there's no __eq__ but the == operator will use id() |
| Yhg1s | object.__eq__ always exists, though. |
| AStorm | Hm? |
| Yhg1s | oh, hm, it does not. |
| AStorm | Let me check... |