Antoon Pardon wrote:
Would you have us construct two related classes each time we find
ourselves in such a situation and copy an object from one
class to the other depending on the circumstances?

Python itself seems to think so, given the pairings of set/frozenset & list/tuple.

Using genuinely immutable objects as dictionary keys is much easier than saying "while this object is part of a dictionary, don't alter it's hash value or comparison results". Instead, the immutable version is provided to say "alterations are not allowed on this copy"

You can certainly *do* the former (using __hash__ and appropriate comparison overrides), but it isn't particularly easy to do correctly, and hence usually isn't a great idea unless copies are *really* expensive (and even then, a shallow copy approach can often suffice).

Cheers,
Nick.

--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---------------------------------------------------------------
            http://boredomandlaziness.skystorm.net
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to