summaryrefslogtreecommitdiffstats
path: root/Lib/typing.py
diff options
context:
space:
mode:
authorMatthew Rahtz <matthew.rahtz@gmail.com>2022-04-16 04:24:28 (GMT)
committerGitHub <noreply@github.com>2022-04-16 04:24:28 (GMT)
commitf2bc12f0d5297899b57f3fa688b24f3c1d1bee7b (patch)
treed0d8734dd9ab6258a8997b809fa05cb60d9f9c4d /Lib/typing.py
parent468314cc8bfdb6fd328cbbbb7d0807728f25e043 (diff)
downloadcpython-f2bc12f0d5297899b57f3fa688b24f3c1d1bee7b.zip
cpython-f2bc12f0d5297899b57f3fa688b24f3c1d1bee7b.tar.gz
cpython-f2bc12f0d5297899b57f3fa688b24f3c1d1bee7b.tar.bz2
bpo-43224: Add tests for TypeVarTuple substitution in Annotated (GH-31846)
Diffstat (limited to 'Lib/typing.py')
-rw-r--r--Lib/typing.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/Lib/typing.py b/Lib/typing.py
index 1b584be..b26adc6 100644
--- a/Lib/typing.py
+++ b/Lib/typing.py
@@ -2080,6 +2080,17 @@ class Annotated:
OptimizedList = Annotated[List[T], runtime.Optimize()]
OptimizedList[int] == Annotated[List[int], runtime.Optimize()]
+
+ - Annotated cannot be used with an unpacked TypeVarTuple::
+
+ Annotated[*Ts, Ann1] # NOT valid
+
+ This would be equivalent to
+
+ Annotated[T1, T2, T3, ..., Ann1]
+
+ where T1, T2 etc. are TypeVars, which would be invalid, because
+ only one type should be passed to Annotated.
"""
__slots__ = ()
@@ -2093,6 +2104,9 @@ class Annotated:
raise TypeError("Annotated[...] should be used "
"with at least two arguments (a type and an "
"annotation).")
+ if _is_unpacked_typevartuple(params[0]):
+ raise TypeError("Annotated[...] should not be used with an "
+ "unpacked TypeVarTuple")
msg = "Annotated[t, ...]: t must be a type."
origin = _type_check(params[0], msg, allow_special_forms=True)
metadata = tuple(params[1:])