Repository navigation
Fix nested dataclass check in StaticDataclass - #2939
Open
Nas01010101 wants to merge 1 commit into
Open
Nas01010101 wants to merge 1 commit into
Nas01010101 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.
Fixes #2938.
StaticDataclass.__post_init__checks that every field holding a dataclass is itself aStaticDataclass. The loop iteratesfor v, field in zip(values, fields)but testscur_value, a variable left over from the hash-by-id loop. That variable always holds the last field's value, so a plain dataclass in any field other than the last is accepted, and one in the last field is reported under the first field's name.The change tests
vinstead ofcur_value, which also removes thepyrefly: ignore[unbound-name].The existing
test_dataclass_field_is_staticpasses onmainonly becauseNotAStaticDataclassuseseq=False, so it hashes by id and the hash-by-id check raises first. The new test puts a frozen dataclass that hashes by value in the first of two fields. It fails onmainand passes with this change.Testing:
pytest torax/_src/tests/static_dataclass_test.py: 20 passed with the change; with the fix reverted, the new test fails withTypeError not raised.pytest -n 3 torax/_srcwithTORAX_JAXTYPING=True TORAX_ERRORS_ENABLED=True: 3046 passed, 25 skipped, 0 failed.pyink --checkon both files: no changes.