Conversation
This branch has not been deployed
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 drops 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.
The class state now keeps each explicit assignment. When a value is identical to an attribute of a direct base, it records which base supplies that value and restores a child-owned binding on load. This avoids serializing the aliased value as part of the child state and allows aliases to unpicklable base attributes, such as a
threading.Lock, to roundtrip. For an importable base whose attribute changes before loading, the restored binding uses the base's current value, consistent with loading that base by reference. If the class already exists in cloudpickle's dynamic class tracker, its existing child-owned binding is retained.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.Reproducer (run as a script):
On upstream
4af5936, the final assertion fails withb"2\n". It passes with this fix.Regression tests cover constants and methods, single and multiple inheritance, protocols 2 and 5, an importable base with an unpicklable lock, an importable base changed before loading, and a class already present in the dynamic class tracker. Reverting the new base-attribute reference code makes the lock regression fail for both protocols.
Local validation on Python 3.14.7: 280 passed, 12 skipped, 2 xfailed. Ruff passes across the repository; Black passes on all changed files. The notebook tests used a temporary kernel spec for the local Python installation.