Repository navigation
Fix Annotated PEP 695 type aliases - #813
Open
arindamsikder wants to merge 2 commits into
Open
arindamsikder wants to merge 2 commits into
arindamsikder wants to merge 2 commits into
Conversation
This branch has not been deployed
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
Annotatedvalues hidden behind PEP 695 aliases during serialization, deserialization, and recursive type discoveryProblem
A field declared with
type Natural = Annotated[...]reaches pyserde as aTypeAliasType. After the alias is unwrapped, both renderers reject the remainingAnnotatedtype, while the compatibility walkers stop before discovering nested dataclasses, unions, and literals. The equivalent legacy alias syntax already works.Solution
Render the underlying
Annotatedtype without mutating the original field annotation, and teach all three recursive compatibility walkers to traverse the wrapped type. Regression coverage includes native aliases, alias chains, nested containers, unions, literals, standalone decorators, field options, and unhashable metadata when type checking is explicitly disabled.Python 3.12/3.13 CI correction
The original tests incorrectly required strict end-to-end support for the distinct
typing_extensions.TypeAliasTypeimplementation. With the locked Beartype 0.22.6, Python 3.12.15 and 3.13.16 reject even a plain backport alias toint, both on pristine pyserde and in a Beartype-only control. This is separate from #805.The follow-up changes tests only: strict end-to-end cases use the native alias, retaining their validation assertions. Twelve direct renderer cases exercise backport alias chains with primitive/container types, immutable/mutable metadata, and annotation preservation; the backport walker regression still covers nested dataclass, union, and literal discovery. No new skip/xfail, disabled validator, dependency bump, or runtime workaround was added. This PR does not fix strict backport-alias validation in Beartype.
Testing
All repository execution ran in credential-free, network-isolated Bubblewrap sandboxes, with isolation/import canaries before tests.
Current follow-up:
python -m pytest tests/test_type_alias.py -qreproduced 5 failed, 18 passed on each.python -m pytest tests/test_type_alias.py tests/test_compat.py tests/test_se.py tests/test_de.py -q: 63 passed on each of Python 3.12/3.13. Overmounting pristine pre-fixserde/with those same tests: 23 failed, 40 passed; restored source passes.python -m pytest tests --doctest-modules serde -q -n 2: Python 3.11 5,290 passed / 3 skipped; Python 3.12 and 3.13 each 5,308 passed / 3 skipped; Python 3.14 5,320 passed / 2 skipped / 1 xfailed. Existing exclusions/xfails remain unchanged.orjsonandsqlalchemyinstalled together: Python 3.12/3.13 each 5,350 passed / 2 skipped; pristine baseline 5,327 passed / 2 skipped on each.make check: whitespace, EOF, Black, Pyright, Ruff, and Mypy all passed on pristine baseline and the final diff.python examples/runner.py: passed on Python 3.14.The offline environments use the repository's locked dependency versions; the canonical pre-commit command reused an isolated lock-version environment with
UV_NO_SYNC=1. Initial concurrent test/lint timeouts were retained; complete serialized runs above passed. Local workers were limited to two instead of-nauto. The optional dependency runs above combine the two extras rather than reproducing CI's separate sync stages; hosted CI remains authoritative. The original implementation's wheel/sdist build passed; packaging was not repeated for this test-only follow-up. Earlier all-extras timeouts remain historical limitations, not passes.Related Issue
Fixes #805
AI-assisted implementation and follow-up using OpenAI Codex; the final diffs received independent automated review and were validated as described above.