Skip to content

Fix Annotated PEP 695 type aliases - #813

Open
arindamsikder wants to merge 2 commits into
yukinarit:mainfrom
arindamsikder:fix/annotated-type-aliases
Open

arindamsikder wants to merge 2 commits into
yukinarit:mainfrom
arindamsikder:fix/annotated-type-aliases

Conversation

@arindamsikder

@arindamsikder arindamsikder commented Oct 18, 2026 •

Copy link
Copy Markdown

Summary

  • handle Annotated values hidden behind PEP 695 aliases during serialization, deserialization, and recursive type discovery
  • preserve original field annotations, validators, aliases, defaults, skip behavior, and custom handlers
  • cover strict native-alias integration and backport renderer/walker behavior separately

Problem

A field declared with type Natural = Annotated[...] reaches pyserde as a TypeAliasType. After the alias is unwrapped, both renderers reject the remaining Annotated type, while the compatibility walkers stop before discovering nested dataclasses, unions, and literals. The equivalent legacy alias syntax already works.

Solution

Render the underlying Annotated type 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.TypeAliasType implementation. With the locked Beartype 0.22.6, Python 3.12.15 and 3.13.16 reject even a plain backport alias to int, 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:

  • Original PR head on Python 3.12.15 and 3.13.16: python -m pytest tests/test_type_alias.py -q reproduced 5 failed, 18 passed on each.
  • Affected tests: 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-fix serde/ 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.
  • The same full targets with locked orjson and sqlalchemy installed 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.
  • Independent automated diff review: no blocking security or logic findings.

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.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Annotated with type statement is not supported

1 participant