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

anatoly techtonik techtonik at gmail.com
Fri Feb 24 11:36:46 CET 2012

On Fri, Feb 24, 2012 at 4:08 AM, Nick Coghlan <ncoghlan at gmail.com> wrote:
> 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.

I also think about reverse process of removing things that were proved
to be underused. That probably requires AST spider that crawls
existing Python project to see how various constructs are used.
anatoly t.

More information about the Python-ideas mailing list