Repository navigation
Serializer: store classes as references, add aliases and schema versions - #48
Merged
Merged
Conversation
- Store a class value as {'__type__': 'module.Class'} and resolve it through
the allowlist. Before, a class value became None without an error.
- Serialize set and frozenset in sorted order. Accept a class, enum or tuple
as a dict key.
- Add register_class_alias(old_path, new_path) so that payloads load after a
class moves or is renamed.
- Add _schema_version, _migrate() and SchemaVersionError. Version 0 is not
written, so existing payloads do not change.
- Raise MissingClassError when a payload names a class or module that the
installed code does not have.
- PropagationMixin: do not call _set_parent on a class value.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
|
All contributors have signed the CLA. Thank you! |
Collaborator
Author
|
I have read the CLA Document and I hereby sign the CLA |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
0x1r1s
added a commit
that referenced
this pull request
Sep 29, 2026
0.2.24 is already on PyPI and is now used by PR #48. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
nicholas9182
approved these changes
Sep 29, 2026
Keep dev's {'__set__': True, 'items': [...]} set payload (released in
0.2.24) with sorted items; reader also accepts the list-valued form.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Summary
The serializer stores a class as a reference (its module path), never as code. This PR extends that approach so that
SerializerMixincan save types and sets, and so that saved data stays readable after the code changes.{'__type__': 'module.Class'}and resolved through the allowlist. Before this change, a class value becameNonewith no error.setandfrozensetare saved in sorted order, so equal sets give equal bytes. A class, an enum or a tuple can now be a dict key. Before this change, msgpack refused these keys.register_class_alias(old_path, new_path)loads old payloads after a class moves or is renamed. Aliases can form a chain. A cycle is refused. The allowlist check applies to the new path._schema_versionand override_migrate(data, version). A load calls_migratewhen the payload is older than the class. A payload that is newer than the class raisesSchemaVersionError. Version 0 is not written, so the payloads of existing classes do not change.MissingClassError(aValueError). The message names the path and refers toregister_class_alias.PropagationMixinno longer calls_set_parenton a class value after a load.Backward compatibility
devand with this branch. The bytes are the same for all 73. Each object loads again.ValueError, so code that catchesValueErrorarounddeserializecontinues to work.Tests
test/test_serializer_mixin.py: 28 new tests for type references, sets, aliases, missing classes and schema versions. The full steer-core suite passes.Next step
steer-opencell-productionuses these features to save machines. After this PR is merged and released, that package must raise itssteer-coreversion bound.