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

Nick Coghlan ncoghlan at gmail.com
Tue Feb 28 01:26:38 CET 2012

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


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-ideas mailing list