Skip to content
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
12 changes: 8 additions & 4 deletions mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -5904,7 +5904,9 @@ def visit_type_alias_stmt(self, s: TypeAliasStmt) -> None:
python_3_12_type_alias=True,
)
alias_node.default_depends = default_depends
s.alias_node = alias_node
if s.alias_node is None:
# If there is an existing node, it will be modified in-place.
s.alias_node = alias_node

updated = False
if (
Expand Down Expand Up @@ -6329,9 +6331,11 @@ def analyze_type_application(self, expr: IndexExpr) -> None:
if types is None:
return
base = expr.base
expr.analyzed = TypeApplication(base, types)
expr.analyzed.line = expr.line
expr.analyzed.column = expr.column
if not isinstance(expr.analyzed, TypeAliasExpr):
# Do not re-point r.h.s. of a type alias, it is all set.
expr.analyzed = TypeApplication(base, types)
expr.analyzed.line = expr.line
expr.analyzed.column = expr.column

if isinstance(base, RefExpr) and base.fullname == "librt.vecs.vec":
# Apply restrictions specific to vec
Expand Down
11 changes: 11 additions & 0 deletions test-data/unit/check-python312.test
Original file line number Diff line number Diff line change
Expand Up @@ -2401,3 +2401,14 @@ reveal_type(baz(objs)) # N: Revealed type is "builtins.list[__main__.B | __main
reveal_type(baz(objs_a)) # N: Revealed type is "builtins.list[__main__.B | __main__.C]"
[builtins fixtures/tuple.pyi]
[typing fixtures/typing-full.pyi]

[case testDeferredNestedTupleAliasNewSyntax]
type Inner = tuple[int, str]
type Outer = tuple[bool, *Inner]

class K(Base):
q: list[Outer] = list()

class Base: ...
reveal_type(K.q) # N: Revealed type is "builtins.list[tuple[builtins.bool, builtins.int, builtins.str]]"
[builtins fixtures/tuple.pyi]
13 changes: 13 additions & 0 deletions test-data/unit/check-typevar-tuple.test
Original file line number Diff line number Diff line change
Expand Up @@ -3232,3 +3232,16 @@ def foo(x, *args):
def test(f: Callable[[object], object]) -> None: ...
test(foo) # E: Argument 1 to "test" has incompatible type overloaded function; expected "Callable[[object], object]"
[builtins fixtures/tuple.pyi]

[case testDeferredNestedTupleAlias]
from typing import Unpack

Inner = tuple[int, str]
Outer = tuple[bool, Unpack[Inner]]

class K(Base):
q: list[Outer] = list()

class Base: ...
reveal_type(K.q) # N: Revealed type is "builtins.list[tuple[builtins.bool, builtins.int, builtins.str]]"
[builtins fixtures/tuple.pyi]
Loading