Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Unpack imported from typing #14378

Merged
merged 2 commits into from
Jan 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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