[Python-Dev] Add a frozendict builtin type (original) (raw)
André Malo nd at perlig.de
Thu Mar 1 21:27:17 CET 2012
- Previous message: [Python-Dev] Add a frozendict builtin type
- Next message: [Python-Dev] Spreading the Python 3 religion
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
- Serhiy Storchaka wrote:
01.03.12 16:47, André Malo написав(ла): > On Thursday 01 March 2012 15:17:35 Serhiy Storchaka wrote: >> This is the first rational use of frozendict that I see. However, a >> deep copy is still necessary to create the frozendict. For this case, >> I believe, would be better to "freeze" dict inplace and then >> copy-on-write it. > > In my case it's actually a half one. The data mostly comes from > memcache ;) I'm populating the object and then I'm done with it. People > wanting to modify it, need to copy it, yes. OTOH usually a shallow copy > is enough (here).
What if people modify dicts in deep?
that's the "here" part. They can't [1]. These objects are typically ROLists of RODicts. Maybe nested deeper, but all RO* or other immutable types.
I cheated, by deepcopying always in the cache, but defining deepcopy for those RO* objects as "return self".
nd
[1] Well, an attacker could, because it's still based on regular dicts and lists. But thatswhy it's not a security feature, but a safety net (here).
"Solides und umfangreiches Buch" -- aus einer Rezension
<http://pub.perlig.de/books.html#apache2>
- Previous message: [Python-Dev] Add a frozendict builtin type
- Next message: [Python-Dev] Spreading the Python 3 religion
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]