Update with pickle

Nicolas Fleury nid_oizo at yahoo.com_remove_the_
Wed May 26 18:36:09 EDT 2004


Matteo Dell'Amico wrote:
> Well, it's not possible: variables are just names attached to objects, 
> and while you can assign a name to an object, you *can't* change the 
> object's type, or replace an object with another one.

I think it is acceptable that this pickle.update function would only 
accept reference of same type and raise an exception otherwise.  The 
point of pickle.update would be to not "replace an object with another 
one" but to call __init__ on an existing object.

> And I think that copying __dict__ is a hack: it wouldn't work, for 
> instance, with builtin types, when __slots__ are used, or when you are 
> using properties.

I agree it's a hack.  It think the best solution would be direct support 
by pickle module and according to Stefan's post, I'm not the only one 
with that need (by the way, not only __dict__ can be copied, all other 
necessary stuff also).

> A transparent proxy is a clean way to do it: through delegation, it 
> would work with any kind of object, changes in code are localized in the 
> load/save part, and the rest of the application wouldn't even notice.

I have experienced problems with proxies.  They are never totally 
transparent, even if all access to members and methods work.  For 
example, a call to isinstance with the proxy would fail because it is 
not of the same type as the aggregated object.  All these glitches can 
be fixed, but it makes the solution less transparent.

Another problem is that the solution is intrusive, meaning that all 
objects that are dumped must have a corresponding proxy, while the best 
solution would be to keep this detail at one place and only in the 
load/dump part of the application.  So on the design point of vue, I 
prefer the hack.

Regards,
Nicolas



More information about the Python-list mailing list