Question about unpickling dict subclass with custom __setstate__

M

Matthew Wilson

I subclassed the dict class and added a __setstate__ method because I
want to add some extra steps when I unpickle these entities. This is a
toy example of what I am doing:

class Entity(dict):

def __setstate__(self, d):

log.debug("blah...")

Based on my experiments, the data in d *IS NOT* the data stored in my
instances when I do stuff like:

e = Entity()
e['a'] = 1

Instead, the stuff in d is the data stored when I do stuff like:

e.fibityfoo = 99

Here's my question:

Is there anything I have to do to make sure that my real dictionary data
is correctly reloaded during the unpickle phase? In other words, should
I run super(Entity, self).__setstate__(d) or something like that?

TIA

Matt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,197
Messages
2,571,040
Members
47,635
Latest member
SkyePurves

Latest Threads

Top