Preserve explicit subclass overrides when pickling dynamic classes - #600
Open
soodoku wants to merge 1 commit into
Open
Preserve explicit subclass overrides when pickling dynamic classes#600soodoku wants to merge 1 commit into
soodoku wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a subclass explicitly assigns the same object as a base attribute, cloudpickle removes that assignment from the serialized class state. In a fresh process, updating the base then changes the subclass too, despite its explicit override. Fixes #584.
Preserve the class's own dictionary entries. Python already excludes merely inherited attributes from this dictionary; sharing an object with a base attribute does not make an explicit assignment redundant. The subprocess tests cover constants and methods, single and multiple inheritance, and protocols 2 and 5. They start a worker before defining the classes so class tracking cannot mask the failure.
Class construction already sets
__module__, so state restoration skips a redundant assignment of that attribute. This avoids triggering custom metaclass setters twice while still restoring a module value that changed on an existing tracked class. Both cases have regression tests.Reproducer (run as a script):
On upstream
4af5936, the final assertion fails withb"2\n". It passes with this fix.Validation on macOS:
__module__. All eight new cases pass with the final fix.cloudpickleandtests.python -m buildbuilds the source distribution and a wheel from it;twine check --strict dist/*passes. A fresh environment using the installed wheel, outside the source checkout, passes 274 tests, with 10 skipped and 2 xfailed. The README's functional examples and the reproducer pass against that wheel.Full suites use
PYTHONPATH='.:tests' python -m pytest -qwith the development dependencies plus NumPy and SciPy. The wheel suite uses a separate copy of the tests because the existing source distribution omits them (#555).