[Python-Dev] 'unhashable type' and new style classes

Guido van Rossum guido@python.org
Mon, 30 Dec 2002 17:26:50 -0500


> On maandag, dec 30, 2002, at 17:30 Europe/Amsterdam, Guido van Rossum 
> wrote:
> > The default implementation of __hash__ must match the default
> > implementation of __cmp__ (and rich comparisons, __eq__ etc.).  So the
> > default implementation cannot raise an exception, because objects are
> > defined to be immutable by default.  (Maybe this was a mistake, but
> > it's not so easy to change without causing backwards
> > incompatibilities.)
> 
> Is it an option to enforce that these methods are overridden together, 
> then? I.e. if you override any of them you must override all of them, 
> otherwise you get a warning?

That's nice, but I'm not sure I can see right away how to do the
warning.  Also, there are cases where a base class defines both
properly, and then a subclass overrides one but not the other.  Is
that worth a warning or not?  That depends on how they change it!

--Guido van Rossum (home page: http://www.python.org/~guido/)