Skip to content

Commit

Permalink
Fix Unpack imported from typing (#14378)
Browse files Browse the repository at this point in the history
Add missing check for `typing.Unpack` to fix running with `--python
3.11`.

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
  • Loading branch information
cdce8p and JelleZijlstra committed Jan 2, 2023
1 parent c831654 commit 5f480f3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -1881,7 +1881,7 @@ def analyze_unbound_tvar(self, t: Type) -> tuple[str, TypeVarLikeExpr] | None:
# It's bound by our type variable scope
return None
return unbound.name, sym.node
if sym and sym.fullname == "typing_extensions.Unpack":
if sym and sym.fullname in ("typing.Unpack", "typing_extensions.Unpack"):
inner_t = unbound.args[0]
if not isinstance(inner_t, UnboundType):
return None
Expand Down
12 changes: 12 additions & 0 deletions test-data/unit/check-python311.test
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,15 @@ try:
except* (RuntimeError, ExceptionGroup) as e: # E: Exception type in except* cannot derive from BaseExceptionGroup
reveal_type(e) # N: Revealed type is "builtins.ExceptionGroup[Union[builtins.RuntimeError, Any]]"
[builtins fixtures/exception.pyi]

[case testBasicTypeVarTupleGeneric]
from typing import Generic, TypeVarTuple, Unpack

Ts = TypeVarTuple("Ts")

class Variadic(Generic[Unpack[Ts]]):
...

variadic: Variadic[int, str]
reveal_type(variadic) # N: Revealed type is "__main__.Variadic[builtins.int, builtins.str]"
[builtins fixtures/tuple.pyi]
2 changes: 2 additions & 0 deletions test-data/unit/lib-stub/typing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ NoReturn = 0
Never = 0
NewType = 0
ParamSpec = 0
TypeVarTuple = 0
Unpack = 0
Self = 0
TYPE_CHECKING = 0

Expand Down

0 comments on commit 5f480f3

Please sign in to comment.