Skip to content

Commit d8ce20a

Browse files
committed
Document that nested Annotated types referenced through a type alias are not flattened
1 parent 6666b38 commit d8ce20a

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

Doc/library/typing.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,6 +1402,14 @@ These can be used as types in annotations. They all support subscription using
14021402
int, ValueRange(3, 10), ctype("char")
14031403
]
14041404

1405+
However, this does not apply to ``Annotated`` types referenced through a type
1406+
alias::
1407+
1408+
type From3To10[T] = Annotated[T, ValueRange(3, 10)]
1409+
assert Annotated[From3To10[int], ctype("char")] != Annotated[
1410+
int, ValueRange(3, 10), ctype("char")
1411+
]
1412+
14051413
* Duplicated metadata elements are not removed::
14061414

14071415
assert Annotated[int, ValueRange(3, 10)] != Annotated[

Lib/typing.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2239,6 +2239,12 @@ def Annotated(self, *params):
22392239
22402240
assert Annotated[Annotated[T, Ann1, Ann2], Ann3] == Annotated[T, Ann1, Ann2, Ann3]
22412241
2242+
However, this does not apply to Annotated types referenced through
2243+
a type alias::
2244+
2245+
type A[T] = Annotated[T, Ann1, Ann2]
2246+
assert Annotated[A[T], Ann3] != Annotated[T, Ann1, Ann2, Ann3]
2247+
22422248
- Instantiating an annotated type is equivalent to instantiating the
22432249
underlying type::
22442250

0 commit comments

Comments
 (0)