Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always normalize regular tuple fallback to tuple[Any, ...] #18603

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 0 additions & 5 deletions mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -8484,11 +8484,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], ProperType) or not isinstance(
fallback.args[0], AnyType
):
fallback = fallback.copy_modified(args=[AnyType(TypeOfAny.special_form)])
self.partial_fallback = fallback
self.items = items
self.implicit = implicit
Expand Down