Skip to content

Fix JSON decoding for parameterized PEP 695 type aliases#780

Merged
hramezani merged 2 commits intomainfrom
fix/parameterized-type-alias-decoding
Feb 18, 2026
Merged

Fix JSON decoding for parameterized PEP 695 type aliases#780
hramezani merged 2 commits intomainfrom
fix/parameterized-type-alias-decoding

Conversation

@hramezani
Copy link
Copy Markdown
Member

Summary

  • Fixes Json decode not working when the field's annotation is defined by using the type statement #778
  • When a parameterized PEP 695 type alias (e.g., type MaxLen[_T] = Annotated[_T, Len(max_length=4)]) was used as a field annotation like MaxLen[list[str]], JSON decoding was skipped because __value__ returned the raw Annotated[_T, ...] with unsubstituted TypeVars
  • Added _resolve_type_alias() and _substitute_typevars() helpers that properly substitute type parameters with concrete types when resolving parameterized TypeAliasType annotations
  • Replaced inline annotation = annotation.__value__ pattern in _annotation_is_complex(), _get_field_metadata(), and _extract_field_info() with the new helper

Test plan

  • Added test_annotated_with_parameterized_type_alias covering all variants: traditional TypeVar alias, parameterized TypeAliasType, with ForceDecode, and with NoDecode
  • All 186 tests in test_settings.py pass
  • Full test suite passes (361 passed, 56 skipped, 1 pre-existing unrelated failure)

🤖 Generated with Claude Code

@hramezani hramezani enabled auto-merge (squash) February 18, 2026 08:21
@hramezani hramezani merged commit acf8c14 into main Feb 18, 2026
19 checks passed
@hramezani hramezani deleted the fix/parameterized-type-alias-decoding branch February 18, 2026 08:22
@hramezani hramezani mentioned this pull request Feb 19, 2026
2 tasks
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.

Json decode not working when the field's annotation is defined by using the type statement

1 participant