[Python-ideas] Support other dict types for type.__dict__
aquavitae69 at gmail.com
Fri Feb 24 06:33:48 CET 2012
On Fri, Feb 24, 2012 at 3: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.
> Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
> Python-ideas mailing list
> Python-ideas at python.org
Can't this also be done using metaclasses?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas