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
4 changes: 3 additions & 1 deletion mypy/semanal_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,9 @@ def calculate_tuple_fallback(typ: TupleType) -> None:
):
items.append(unpacked_type.args[0])
else:
raise NotImplementedError
# This is called before semanal_typeargs.py fixes broken unpacks,
# where the error should also be generated.
items.append(AnyType(TypeOfAny.from_error))
else:
items.append(item)
fallback.args = (make_simplified_union(items),)
Expand Down
2 changes: 1 addition & 1 deletion mypy/typeanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ def try_analyze_special_unbound_type(self, t: UnboundType, fullname: str) -> Typ
)
elif fullname == "typing.Union":
items = self.anal_array(t.args)
return UnionType.make_union(items)
return UnionType.make_union(items, line=t.line, column=t.column)
elif fullname == "typing.Optional":
if len(t.args) != 1:
self.fail(
Expand Down
10 changes: 10 additions & 0 deletions test-data/unit/check-python312.test
Original file line number Diff line number Diff line change
Expand Up @@ -2121,3 +2121,13 @@ class A: ...

x1: Alias1[A] # ok
x2: Alias2[A] # ok

[case testUndefinedUnpackInPEP696Base]
# Typo below is intentional.
class MyTuple[*Ts](tuple[*TS]): # E: Name "TS" is not defined
...

x: MyTuple[int, str]
reveal_type(x[0]) # N: Revealed type is "Any"
[builtins fixtures/tuple.pyi]
[typing fixtures/typing-full.pyi]
24 changes: 24 additions & 0 deletions test-data/unit/check-typevar-tuple.test
Original file line number Diff line number Diff line change
Expand Up @@ -2692,3 +2692,27 @@ tuple(a)
(x,) = a
(_,) = a
[builtins fixtures/tuple.pyi]

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

Ts = TypeVarTuple("Ts")

class MyTuple(tuple[Unpack[TsWithTypo]], Generic[Unpack[Ts]]): # E: Name "TsWithTypo" is not defined
...

x: MyTuple[int, str]
reveal_type(x[0]) # N: Revealed type is "Any"
[builtins fixtures/tuple.pyi]

[case testNoCrashOnInvalidUnpackInBase]
from typing import TypeVarTuple, Generic, Unpack, Union

Ts = TypeVarTuple("Ts")

class MyTuple(tuple[Unpack[Union[int, str]]], Generic[Unpack[Ts]]): # E: "Union[int, str]" cannot be unpacked (must be tuple or TypeVarTuple)
...

x: MyTuple[int, str]
reveal_type(x[0]) # N: Revealed type is "Any"
[builtins fixtures/tuple.pyi]