Skip to content

Commit

Permalink
Normalize tuple fallback to tuple[Any, ...] in constructor if it isn'…
Browse files Browse the repository at this point in the history
…t special
  • Loading branch information
sterliakov committed Feb 5, 2025
1 parent 237933a commit 558a8f7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
5 changes: 0 additions & 5 deletions mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -8485,11 +8485,6 @@ def visit_type_var(self, t: TypeVarType) -> bool:
# multi-step type inference.
return t.id.is_meta_var()

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


class SetNothingToAny(TypeTranslator):
"""Replace all ambiguous Uninhabited types with Any (to avoid spurious extra errors)."""
Expand Down
6 changes: 6 additions & 0 deletions mypy/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -2415,6 +2415,12 @@ def __init__(
implicit: bool = False,
) -> None:
super().__init__(line, column)
if fallback.type and fallback.type.fullname == "builtins.tuple":
assert len(fallback.args) == 1
if not isinstance(fallback.args[0], AnyType):
fallback = fallback.copy_modified(
args=[AnyType(TypeOfAny.implementation_artifact)]
)
self.partial_fallback = fallback
self.items = items
self.implicit = implicit
Expand Down

0 comments on commit 558a8f7

Please sign in to comment.