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

Nick Coghlan ncoghlan at gmail.com
Fri Feb 24 02:08:05 CET 2012


On Fri, Feb 24, 2012 at 9:34 AM, Victor Stinner
<victor.stinner at haypocalc.com> wrote:
> Hi,
>
> I'm trying to create read-only objects using a "frozendict" class.
> frozendict is a read-only dict. I would like to use frozendict for the
> class dict using a metaclass, but type.__new__() expects a dict and
> creates a copy of the input dict.

Do you have a particular reason for doing it that way rather than just
overriding __setattr__ and __delattr__ to raise TypeError?

Or overriding the __dict__ descriptor to return a read-only proxy?

There are a *lot* of direct calls to the PyDict APIs in the object
machinery. Without benchmark results clearly showing a negligible
speed impact, I'd be -1 on increasing the complexity of all that code
(and making it slower) to support niche use cases that can already be
handled a couple of other ways.

Cheers,
Nick.

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



More information about the Python-ideas mailing list