Skip to content

Usage of updater in VersionedUnpickler is undocumented and maybe redundant #238

@kitchoi

Description

@kitchoi

The VersionedUnpickler accepts an updater object:

def __init__(self, file, updater=None):
Unpickler.__init__(self, file)
self.updater = updater

This was supposed to be its "interface":

class Updater:
"""An abstract class to provide functionality common to the updaters."""
def get_latest(self, module, name):
"""The refactorings dictionary contains mappings between old and new
module names. Since we only bump the version number one increment
there is only one possible answer.
"""

But from where it is used, there are more features expected of this interface, e.g. it is expected to have an attribute called setstates which is a dictionary:

fn = self.updater.setstates.get((module, name), False)

The structure of this dictionary is not documented (and there seem to be no tests for it). It seems to be used for monkeypatching a class __setstate__ (a global state that does not belong to apptools!), but it may not be restored.
Monkeypatching here in the code path if VersionedUnpickler.updater is not None:

# hook up our __setstate__ which updates self.__dict__
setattr(klass, "__setstate__", __replacement_setstate__)

To be restored if some other unpickler without an updater came across the same class:

# restore the original __setstate__ if necessary
fn = getattr(klass, "__setstate_original__", False)
if fn:
setattr(klass, "__setstate__", fn)

It is possible that no one uses an updater with the VersionedUnpickler so this monkeypatching is never exercised. I have not checked if there are other uses of an updater anywhere else. It could be a feature that can be removed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions