Question about unpickling dict subclass with custom __setstate__

Matthew Wilson matt at tplus1.com
Thu Sep 10 19:09:34 EDT 2009


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




More information about the Python-list mailing list