You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support string and recursive type aliases, sentinels and fix dataclass with custom init - #991
Support for TypeAliasType aliases whose value is a string, e.g. TypeAliasType("Json", "str | list[Json]"), evaluated in the module that defines the alias.
Support for PEP 661 sentinels as types, e.g. x: int | MISSING = MISSING, accepting only the sentinel given as its import path.
Fixed recursive type aliases, e.g. type Json = int | list[Json], failing with RecursionError, including in JSON schema generation.
Fixed sentinel defaults being shown in the help as <UnsetType object at 0x...>, and failing to serialize when the sentinel is not defined in the module of its class.
Fixed dataclasses with init=False and a hand-written __init__ getting parameter types from the fields instead of from __init__, so parameters that are not fields stayed unresolved and valid defaults were rejected.
✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (173e96e) to head (be4df4c).
✅ All tests successful. No failed tests found.
[Medium risk] Extends type system support for aliases, sentinels, and dataclass init.
The PR should not merge until string aliases can recover from early resolution failures and JSON Schema generation terminates for recursive generic aliases.
This PR adds string-valued and recursive type-alias handling, PEP 661 sentinel support, sentinel-default serialization, and a correction for dataclasses with custom initializers.
String-alias resolution can retain an early resolution failure after the referenced name becomes available.
JSON Schema expansion does not terminate for recursive generic aliases whose arguments change at each level.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Alias type hint] --> B{String-valued?}
B -- Yes --> C[Resolve in defining module]
B -- No --> D[Get alias target]
C --> D
D --> E[Parse value or generate JSON Schema]
E --> F{Recursive alias?}
F -- Yes --> G[Build and reference definition]
F -- No --> H[Expand target inline]
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
bugSomething isn't workingenhancementNew feature or request
1 participant
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.
What does this PR do?
TypeAliasTypealiases whose value is a string, e.g.TypeAliasType("Json", "str | list[Json]"), evaluated in the module that defines the alias.x: int | MISSING = MISSING, accepting only the sentinel given as its import path.type Json = int | list[Json], failing withRecursionError, including in JSON schema generation.<UnsetType object at 0x...>, and failing to serialize when the sentinel is not defined in the module of its class.init=Falseand a hand-written__init__getting parameter types from the fields instead of from__init__, so parameters that are not fields stayed unresolved and valid defaults were rejected.Before submitting