On 7/26/20 4:09 PM, Marco Sulla wrote: > You're quite right, but if you don't implement __eq__, the hash of an > object is simply a random integer (I suppose generated from the > address of the object). > > Alternatively, if you want a quick hash, you can use hash(str(obj)) > (if you implemented __str__ or __repr__). > And if you don't implement __eq__, I thought that the default equal was same id(), (which is what the hash is based on too).
The idea was (I thought) that if you implement an __eq__, so that two different object could compare equal, then you needed to come up with some hash function for that object that matched that equality function, or the object is considered unhashable. -- Richard Damon _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/NWVR4JJPJYJLJDVINNYTZSR4AAPKNHXK/ Code of Conduct: http://python.org/psf/codeofconduct/