Skip to content

Commit c2c8c35

Browse files
committed
Silence "need type annotation" from fallback
1 parent 87cf7d5 commit c2c8c35

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

mypy/checker.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8485,6 +8485,11 @@ def visit_type_var(self, t: TypeVarType) -> bool:
84858485
# multi-step type inference.
84868486
return t.id.is_meta_var()
84878487

8488+
def visit_tuple_type(self, t: TupleType, /) -> bool:
8489+
# Exclude fallback to avoid bogus "need type annotation" errors
8490+
# TODO: Maybe erase plain tuples used as fallback in TupleType constructor?
8491+
return self.query_types(t.items)
8492+
84888493

84898494
class SetNothingToAny(TypeTranslator):
84908495
"""Replace all ambiguous Uninhabited types with Any (to avoid spurious extra errors)."""

test-data/unit/check-inference.test

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3886,3 +3886,10 @@ def a4(x: List[str], y: List[Never]) -> None:
38863886
reveal_type(z2) # N: Revealed type is "builtins.list[builtins.object]"
38873887
z1[1].append("asdf") # E: "object" has no attribute "append"
38883888
[builtins fixtures/dict.pyi]
3889+
3890+
[case testTupleJoinFallbackInference]
3891+
foo = [
3892+
(1, ("a", "b")),
3893+
(2, []),
3894+
]
3895+
[builtins fixtures/tuple.pyi]

0 commit comments

Comments
 (0)