Skip to content

Commit bebdf28

Browse files
committed
Maybe this?
1 parent 3989212 commit bebdf28

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

mypy/semanal_typeargs.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ def visit_type_alias_type(self, t: TypeAliasType) -> None:
102102
# If there was already an error for the alias itself, there is no point in checking
103103
# the expansion, most likely it will result in the same kind of error.
104104
get_proper_type(t).accept(self)
105+
self.visit_optional_type(t.alias)
105106

106107
def visit_tuple_type(self, t: TupleType) -> None:
107108
t.items = flatten_nested_tuples(t.items)
@@ -254,6 +255,10 @@ def visit_unpack_type(self, typ: UnpackType) -> None:
254255
def check_type_var_values(
255256
self, name: str, actuals: list[Type], arg_name: str, valids: list[Type], context: Context
256257
) -> bool:
258+
if self.in_type_alias_expr:
259+
# See testValidTypeAliasValues - we do not enforce typevar compatibility
260+
# at the definition site. We check instantiation validity later.
261+
return False
257262
is_error = False
258263
for actual in get_proper_types(actuals):
259264
# We skip UnboundType here, since they may appear in defn.bases,

test-data/unit/check-typevar-tuple.test

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2667,10 +2667,17 @@ class S(tuple[Unpack[Ts]], Generic[T, Unpack[Ts]]):
26672667
def f(self, x: T, /) -> T: ...
26682668
[builtins fixtures/tuple.pyi]
26692669

2670-
[case testNoCrashSubclassingTUpleWithTrivialUnpack]
2670+
[case testNoCrashSubclassingTupleWithTrivialUnpack]
26712671
# https://github.com/python/mypy/issues/19105
26722672
from typing import Unpack
26732673

26742674
class A(tuple[Unpack[tuple[int]]]): ...
26752675
class B(tuple[Unpack[tuple[()]]]): ...
2676+
2677+
a: A
2678+
tuple(a)
2679+
(x,) = a
2680+
2681+
b: B
2682+
(_,) = b # E: Need more than 0 values to unpack (1 expected)
26762683
[builtins fixtures/tuple.pyi]

0 commit comments

Comments
 (0)