-
Notifications
You must be signed in to change notification settings - Fork 21
Description
The VersionedUnpickler accepts an updater object:
apptools/apptools/persistence/versioned_unpickler.py
Lines 111 to 113 in 632a4bf
| def __init__(self, file, updater=None): | |
| Unpickler.__init__(self, file) | |
| self.updater = updater |
This was supposed to be its "interface":
apptools/apptools/persistence/updater.py
Lines 9 to 17 in 632a4bf
| 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:
apptools/apptools/persistence/versioned_unpickler.py
Lines 166 to 167 in 632a4bf
| # 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:
apptools/apptools/persistence/versioned_unpickler.py
Lines 145 to 148 in 632a4bf
| # 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.