[Python-3000-checkins] r45652 - in python/branches/p3yk

Guido van Rossum guido at python.org
Tue Apr 25 20:31:14 CEST 2006


On 4/25/06, skip at pobox.com <skip at pobox.com> wrote:
>
>     >> I think we might need to have a frozenbytes object too.
>
>     Guido> I believe YAGNI. Also, I'm not keen on all these frozen variants.
>     Guido> Hands up who's ever used a frozen set or needed a frozen dict?
>
> On the rare occasion where I've wanted to use a dict (for example) as a key
> in another dict, I've just used tuple(dict1.values()).  In this context I've
> obviously only cared about shallow dicts.

That doesn't quite work since two dicts with the same value could have
different ordering (due to different insert/delete ordering).

> Idle thought alert:
>
> Would it be possible in principle to implement a freeze object which returns
> a proxy that prevents the proxied object from being modified, e.g.:
>
>     def freeze(obj):
>         return Freezer(obj)
>
> where the Freezer class is suitably powerful (knowing at least about all the
> various methods which can modify an object, maybe about some protocol to
> describe methods that can modify an object)?
>
> Now I know it could get messy (__setattr__, list.append, etc.), and like I
> said, this is just an idle thought, but still, if it was possible, you could
> freeze just about anything and not have to create special frozen varieties
> of every containiner type.

It would require the freezer to know about the type of the underlying
object. It also won't be able to prevent someone from reaching in
directly and modifying it anyway.

--
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-3000-checkins mailing list