Identity dictionnary

Jean-Sebastien Roy js at jeannot.org
Sat Feb 28 21:05:48 EST 2004


Hi !

I'm trying to create an object to be used as a key in a dictionary, 
where comparison (for key retrieval) would be done by 'is' instead of 
__eq__.
(__eq__ is defined in this object, but serve another purpose and does 
not return a boolean).

Is defining __hash__ as id(self) sufficient to guarantee that __eq__ 
will never be called by the dict implementation ? (it seems to work in 
practice)
If not, how to ensure __eq__ will never be called ?

Thank you very much in advance !

Regards,

js



More information about the Python-list mailing list