Issue with new-style classes and operators

Greg Ewing see_reply_address at something.invalid
Tue Nov 26 23:27:41 EST 2002


Jan Decaluwe wrote:

> However, if I use inheritance from an immutable 
> type, the subtype is automatically immutable also, right?


Not necessarily -- there's nothing stopping you giving
your subclass some mutable state and providing
methods for mutating it.

However, if you do that, you'd better also override
the __hash__ method and have it raise a suitable
exception, just in case someone tries to use your
type as a dict key.

-- 
Greg Ewing, Computer Science Dept,
University of Canterbury,	
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg




More information about the Python-list mailing list