Skip to content

Commit 0ceb6ad

Browse files
committed
Do not call get_proper_type for traversing type alias: that creates a copy preventing union items update.
1 parent ee1f4c9 commit 0ceb6ad

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

mypy/semanal_typeargs.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def visit_type_alias_type(self, t: TypeAliasType) -> None:
101101
if not is_error:
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.
104-
get_proper_type(t).accept(self)
104+
t.alias.target.accept(self)
105105

106106
def visit_tuple_type(self, t: TupleType) -> None:
107107
t.items = flatten_nested_tuples(t.items)

test-data/unit/check-python312.test

+16
Original file line numberDiff line numberDiff line change
@@ -1972,3 +1972,19 @@ class D:
19721972
class G[Q]:
19731973
def g(self, x: Q): ...
19741974
d: G[str]
1975+
1976+
[case testTypeAliasNormalization]
1977+
from collections.abc import Callable
1978+
from typing import Unpack
1979+
from typing_extensions import TypeAlias
1980+
1981+
type RK_function_args = tuple[float, int]
1982+
type RK_functionBIS = Callable[[Unpack[RK_function_args], int], int]
1983+
1984+
def ff(a: float, b: int, c: int) -> int:
1985+
return 2
1986+
1987+
bis: RK_functionBIS = ff
1988+
res: int = bis(1.0, 2, 3)
1989+
[builtins fixtures/tuple.pyi]
1990+
[typing fixtures/typing-full.pyi]

test-data/unit/check-type-aliases.test

+9-4
Original file line numberDiff line numberDiff line change
@@ -977,13 +977,18 @@ class C(Generic[T]): ...
977977
class D(C[S]): ... # E: Invalid type argument value for "C"
978978

979979
U = TypeVar("U")
980-
A = List[C[U]]
981-
x: A[bytes] # E: Value of type variable "T" of "C" cannot be "bytes"
980+
A = List[C[U]] # E: Type variable "U" not valid as type argument value for "C"
981+
A2 = List[C[T]]
982+
x: A[bytes]
983+
x2: A2[bytes] # E: Value of type variable "T" of "A2" cannot be "bytes"
982984

983985
V = TypeVar("V", bound=int)
986+
V2 = TypeVar("V2", bound=int)
984987
class E(Generic[V]): ...
985-
B = List[E[U]]
986-
y: B[str] # E: Type argument "str" of "E" must be a subtype of "int"
988+
B = List[E[U]] # E: Type argument "U" of "E" must be a subtype of "int"
989+
B2 = List[E[V2]]
990+
y: B[str]
991+
y2: B2[str] # E: Type argument "str" of "B2" must be a subtype of "int"
987992

988993
[case testValidTypeAliasValuesMoreRestrictive]
989994
from typing import TypeVar, Generic, List

0 commit comments

Comments
 (0)