Skip to content

Commit 5f480f3

Browse files
Fix Unpack imported from typing (#14378)
Add missing check for `typing.Unpack` to fix running with `--python 3.11`. Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
1 parent c831654 commit 5f480f3

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

mypy/semanal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1881,7 +1881,7 @@ def analyze_unbound_tvar(self, t: Type) -> tuple[str, TypeVarLikeExpr] | None:
18811881
# It's bound by our type variable scope
18821882
return None
18831883
return unbound.name, sym.node
1884-
if sym and sym.fullname == "typing_extensions.Unpack":
1884+
if sym and sym.fullname in ("typing.Unpack", "typing_extensions.Unpack"):
18851885
inner_t = unbound.args[0]
18861886
if not isinstance(inner_t, UnboundType):
18871887
return None

test-data/unit/check-python311.test

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,15 @@ try:
5151
except* (RuntimeError, ExceptionGroup) as e: # E: Exception type in except* cannot derive from BaseExceptionGroup
5252
reveal_type(e) # N: Revealed type is "builtins.ExceptionGroup[Union[builtins.RuntimeError, Any]]"
5353
[builtins fixtures/exception.pyi]
54+
55+
[case testBasicTypeVarTupleGeneric]
56+
from typing import Generic, TypeVarTuple, Unpack
57+
58+
Ts = TypeVarTuple("Ts")
59+
60+
class Variadic(Generic[Unpack[Ts]]):
61+
...
62+
63+
variadic: Variadic[int, str]
64+
reveal_type(variadic) # N: Revealed type is "__main__.Variadic[builtins.int, builtins.str]"
65+
[builtins fixtures/tuple.pyi]

test-data/unit/lib-stub/typing.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ NoReturn = 0
2727
Never = 0
2828
NewType = 0
2929
ParamSpec = 0
30+
TypeVarTuple = 0
31+
Unpack = 0
3032
Self = 0
3133
TYPE_CHECKING = 0
3234

0 commit comments

Comments
 (0)