On Mon, Feb 27, 2012 at 5:26 PM, Nick Coghlan
On Tue, Feb 28, 2012 at 9:48 AM, Eric Snow
wrote: Such an approach could be applied to lists/tuples, sets/frozensets, strings/bytearrays, bytes/bytearrays, and any other pairings we already have. Unless a frozendict were added as a standard type, dict would not have a match so an __immutable__() method would not be added. In that case, trying to call dict.__immutable__() would be an AttributeError, as happens now.
Folks, before retreading this ground, please make sure to review the relevant past history and decide what (if anything) has changed since Barry proposed the freeze protocol 5 years ago and the PEP was rejected: http://www.python.org/dev/peps/pep-0351/
While hypergeneralisation of this behaviour is tempting, it really isn't a solid abstraction. It's better to make use case specific design decisions that handle all the corner cases relating to mutable vs immutable variants of *particular* container types. The issues you have to consider when converting a list to a tuple are not the same as those that exist when converting bytearray to bytes or a set to a frozenset.
Point taken. :) I knew I'd heard the idea somewhere. I appreciate how Raymond reacts here: http://mail.python.org/pipermail/python-dev/2006-February/060802.html and how Greg Ewing responds here: http://mail.python.org/pipermail/python-dev/2006-February/060822.html My point was that an __immutable__ flag was not a good idea. However, I agree that the generic protocol is likewise inadvisable because it fosters a generic design approach where a generic one is not appropriate. -eric