Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
kitchoi opened this issue Nov 25, 2020 · 0 comments
Open

Comments

@kitchoi
Copy link
Contributor

kitchoi commented Nov 25, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant