Fix enum with tuple values deserialization#765
Open
luxShrine wants to merge 2 commits into
Open
Conversation
added 2 commits
June 17, 2026 16:21
When serializing an enum of tuple values, the tuples are converted into lists. To deserialize back into the expected enum field, these would previously fail as the types did not match. This change now implements a check by reusing the member_value_type of a sequence in the deserialize_enum function, and will properly apply the conversion to a tuple if found.
Appended two tuple enum tests to the existing deserialize enum helper test, to ensure the basic deserialization of the type is done correctly. Added a new test to ensure that the original issue (yukinarit#585) is resolved by testing round trip (de)serialization works with various container types.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #765 +/- ##
==========================================
+ Coverage 90.83% 91.20% +0.37%
==========================================
Files 13 13
Lines 2040 2389 +349
Branches 370 475 +105
==========================================
+ Hits 1853 2179 +326
- Misses 124 138 +14
- Partials 63 72 +9 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
|
The failing UV_FROZEN=1 uv run --frozen ruff check --force-exclude serde/de.pyI opened #767 to fix that main-branch lint regression separately. That PR is now green, so this PR should not need a business-logic change for the formatting failure. |
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.
First noted in (#585), when a tuple field of an enum was serialized into a list, it would not be deserialized into a tuple. This fix aims to patch that gap, by making a minimal change to the enum deserializing helper function, simply checking if the enum field is a tuple and converting it from a list if so.
This is a small patch, and in the original discussion it was noted that a more robust system would be to have a setup that would generate "(de)serialize functions for enum", not unlike what is done currently for
Union. This patch for example only covers a single depth of tuples:("a", ("b", "c"))serializes as["a", ["b", "c"]]and deserializes as("a", ["b", "c"])which would fail to properly align with the original enum value. However, the value in making a small fix like this seemed worthwhile to patch, and leaves the case of more complex fields to the more substantial project of generating deserialization functions for enums.