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.
Problem
A union whose literal discriminator is renamed with
override(rename=...)cannot read back its serialized output. For example, after configuringkindto serialize astype,{'type': 'cat'}fails withKeyError: 'kind'when structured asCat | Dog. The unique-field discriminator already honors renaming, but the literal discriminator still uses the Python attribute name.Change
Build the literal candidates by serialized name using the existing
_overriden_namehelper, retaining the attribute objects to read their literal values. This handles both different attributes renamed to a common discriminator and a common attribute renamed to different keys; the latter falls back to unique-field disambiguation. An empty-string rename is also treated as a valid key.Includes an API version note and changelog entry. The regression tests cover attrs classes, dataclasses, both converter implementations, both validation modes, overrides discovered from hooks, and explicit overrides. All 25 new cases fail on the original implementation.
Validation
On Python 3.14.7:
python -m pytest -q -n 4 tests: 1,019 passed, 15 expected failures.ruff check src/ tests bench: passed.ruff format --check src tests docs/conf.py: passed (115 files).uv.lock.git diff --check: passed.-Wreport the same existingUnknown target name: "factory"warning indefaultdict_structure_factory; the HTML warning was reproduced from a pristine upstream checkout. Sphinx 8.2.3, MyST 4.0.1, and Docutils 0.21.2 matchuv.lock.Developed with Codex assistance; the reproduction and validation above were run locally.