Supported Features
This page documents all features of the Python type annotation ecosystem that are supported by the typeapi package.
| Feature | Supported since | Example | Implemented via | Related PEPs |
|---|---|---|---|---|
| Normal type hint | 1.0.0 | int, MyType, list[str] |
ClassTypeHint |
PEP484, PEP526 |
| Generics in standard collection [^4] | 1.3.0 | list[int], dict[str, str] |
ClassTypeHint |
PEP585 |
| Tuples | 1.0.0 | tuple[int, str], Tuple[Any, ...] |
TupleTypeHint |
PEP484 |
| Union types | 1.0.0 | Union[int, str], int \| str |
UnionTypeHint |
PEP484, PEP604 |
| Sugar syntax for union types [^5] | 1.3.0 | int \| str |
UnionTypeHint |
PEP604 |
| Literals | 1.0.0 | Literal["a", 42] |
LiteralTypeHint |
PEP586 |
| Annotated | 1.0.0 | Annotated[int, "hello_world"] |
AnnotatedTypeHint |
PEP484, PEP593 |
| Type variables | 1.0.0 | TypeVar("T") |
TypeVarTypeHint |
PEP484, PEP646 [^2], PEP695 [^3] |
| Forward references | 1.0.0 | "MyType" |
ForwardRefTypeHint |
PEP484 |
[^2]: PEP646 - Variadic Generics is not currently officially supported. Reflecting type hints using this language feature may fail.
[^3]: PEP695 - Type Parameter Syntax is not currently officially supported. Reflecting type hints using this language feature may fail.
[^4]: Forward references may use the generic syntax introduced in PEP585 - Type Hinting Generics In Standard Collections
in older Python (< 3.9) versions that do not implement this PEP. typeapi will evaluate the forward reference accordingly and
return the correct parameterized generic type hint from the typing module.
[^5]: The union syntax introduced by PEP 604 - Allow writing union types as X | Y may be used in older Python
versions (< 3.10) via forward references. typeapi will evaluate the forward reference accordingly and return the corresponding
typing.Union type hint. Note that the evaluation of new-style union types from string literals will always return a
typing.Union despite the same syntax evaluated in Python versions supporting the syntax returning types.UnionType
instead.