[Python-ideas] Support other dict types for type.__dict__

Eric Snow ericsnowcurrently at gmail.com
Tue Feb 28 01:51:17 CET 2012

On Mon, Feb 27, 2012 at 5:26 PM, Nick Coghlan <ncoghlan at gmail.com> wrote:
> On Tue, Feb 28, 2012 at 9:48 AM, Eric Snow <ericsnowcurrently at gmail.com> 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:


and how Greg Ewing responds here:


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


More information about the Python-ideas mailing list