Repository navigation
fix: reconstruct dataclasses with derived fields #283
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
Merged
Bernd Verst (berndverst)
merged 6 commits into
microsoft:main
from
Shubham-Padkonde:fix/dataclass-derived-fields
Oct 12, 2026
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
266bd6b
fix: reconstruct dataclasses with derived fields
Shubham-Padkonde e416111
fix: preserve non-init state accepted by custom constructors
Shubham-Padkonde 30a1b67
Merge main and preserve dataclass changelog entry
Shubham-Padkonde 9ce0cb7
Merge branch 'main' into fix/dataclass-derived-fields
berndverst b8f0bbc
fix: inspect decorated dataclass initializer signatures
Shubham-Padkonde e3c3b23
Merge branch 'main' into fix/dataclass-derived-fields
berndverst File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please preserve serialized
init=Falsevalues when the actual constructor accepts them.field.initdescribes the generated initializer, not the signature of a handwritten initializer. This currently causes silent data loss for existing supported dataclasses:This also reproduces through
StateShim.get_state(CounterState), and writing the reconstructed state persists the reset value.Recommended change: Omit a non-init field only when the constructor cannot accept it as a keyword argument.
init=Truefields unchanged.init=Falsefield, inspect the actual initializer for an explicit keyword-capable parameter with that name or**kwargs. Pass and recursively coerce the value when accepted; otherwise omit it so generated constructors can initialize derived fields.TypeError: the exception may come from inside user code, and retrying may run side effects twice. Do not blindly restore attributes after construction either, since that could overwrite intentionally computed values or bypass frozen-dataclass semantics.Please add regressions for a handwritten constructor with an explicit non-init parameter and one accepting
**kwargs, including preservation of42through typed entity-state read/write, while retaining the generated/frozen/nested derived-field cases. This is a targeted compatibility fix; arbitrary non-init state with a generated constructor still needs explicit reconstruction semantics, as noted in the review summary.