diff options
author | Alex Waygood <Alex.Waygood@Gmail.com> | 2023-06-08 14:36:30 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-08 14:36:30 (GMT) |
commit | d213c2990f0db62ed39fc5468977f989c2658675 (patch) | |
tree | cd79d5018a36a49c734c34d7cd600597b5846a87 /Lib | |
parent | e830289c52cecd99e5e2291972d648e9b3452a51 (diff) | |
download | cpython-d213c2990f0db62ed39fc5468977f989c2658675.zip cpython-d213c2990f0db62ed39fc5468977f989c2658675.tar.gz cpython-d213c2990f0db62ed39fc5468977f989c2658675.tar.bz2 |
Further improve docs for `typing.Annotated` (#105498)
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/typing.py | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/Lib/typing.py b/Lib/typing.py index 2749774..6f85336 100644 --- a/Lib/typing.py +++ b/Lib/typing.py @@ -2015,7 +2015,7 @@ class Annotated: assert Annotated[int, '$'].__metadata__ == ('$',) - - Nested Annotated are flattened:: + - Nested Annotated types are flattened:: assert Annotated[Annotated[T, Ann1, Ann2], Ann3] == Annotated[T, Ann1, Ann2, Ann3] @@ -2026,15 +2026,17 @@ class Annotated: - Annotated can be used as a generic type alias:: - Optimized = Annotated[T, runtime.Optimize()] - assert Optimized[int] == Annotated[int, runtime.Optimize()] + type Optimized[T] = Annotated[T, runtime.Optimize()] + # type checker will treat Optimized[int] + # as equivalent to Annotated[int, runtime.Optimize()] - OptimizedList = Annotated[List[T], runtime.Optimize()] - assert OptimizedList[int] == Annotated[List[int], runtime.Optimize()] + type OptimizedList[T] = Annotated[list[T], runtime.Optimize()] + # type checker will treat OptimizedList[int] + # as equivalent to Annotated[list[int], runtime.Optimize()] - Annotated cannot be used with an unpacked TypeVarTuple:: - Annotated[*Ts, Ann1] # NOT valid + type Variadic[*Ts] = Annotated[*Ts, Ann1] # NOT valid This would be equivalent to:: |