On Mon, Mar 3, 2008 at 8:23 PM, Michael Bayer <[EMAIL PROTECTED]> wrote: > We define __eq__() all over the place so that would be a lot of > __hash__() methods to add, all of which return id(self). I wonder if > we shouldn't just make a util.Mixin called "Hashable" so that we can > centralize the idea.
Are you sure this is a correct way? Below is an example demonstrating the problem with it: >>> class C(object): ... def __init__(self, value): ... self._value = value ... def __eq__(self, other): ... return self._value==other._value ... def __hash__(self): ... return id(self) ... >>> c1 = C(1) >>> c2 = C(1) >>> c1==c2 True >>> d = {c1: None} >>> c1 in d True >>> c2 in d False I.e. although c2 is equal to c1 and thus should be found in dictionary, it is not. The defined __hash__ method must return equal numbers for equal object. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---