From 3f531e14ed5c6324d99e2e7fe956725a683265d7 Mon Sep 17 00:00:00 2001 From: STerliakov Date: Wed, 5 Feb 2025 01:49:19 +0100 Subject: [PATCH 1/4] Normalize tuple fallback to tuple[Any, ...] in constructor if it isn't special --- mypy/checker.py | 5 ----- mypy/types.py | 6 ++++++ 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/mypy/checker.py b/mypy/checker.py index 999d75678aa45..066e929c52009 100644 --- a/mypy/checker.py +++ b/mypy/checker.py @@ -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).""" diff --git a/mypy/types.py b/mypy/types.py index f700be8871162..76e4ad03ba276 100644 --- a/mypy/types.py +++ b/mypy/types.py @@ -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 From 749f9560a247b0f55f471eb91dee1523d4e5bf7d Mon Sep 17 00:00:00 2001 From: STerliakov Date: Wed, 5 Feb 2025 02:51:20 +0100 Subject: [PATCH 2/4] Fix own typing --- mypy/types.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mypy/types.py b/mypy/types.py index 76e4ad03ba276..26c3e48365e06 100644 --- a/mypy/types.py +++ b/mypy/types.py @@ -2417,7 +2417,9 @@ def __init__( 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): + if not isinstance(fallback.args[0], ProperType) or not isinstance( + fallback.args[0], AnyType + ): fallback = fallback.copy_modified( args=[AnyType(TypeOfAny.implementation_artifact)] ) From a3bd40f1a40d0633c22a593e976bf5b1ebb6ad0e Mon Sep 17 00:00:00 2001 From: STerliakov Date: Wed, 5 Feb 2025 03:02:37 +0100 Subject: [PATCH 3/4] That should be special_form --- mypy/messages.py | 1 + mypy/types.py | 4 +--- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/mypy/messages.py b/mypy/messages.py index 3beb287bcc21c..6b061a379ff64 100644 --- a/mypy/messages.py +++ b/mypy/messages.py @@ -2008,6 +2008,7 @@ def untyped_decorated_function(self, typ: Type, context: Context) -> None: if isinstance(typ, AnyType): self.fail("Function is untyped after decorator transformation", context) else: + breakpoint() self.fail( f'Type of decorated function contains type "Any" ({format_type(typ, self.options)})', context, diff --git a/mypy/types.py b/mypy/types.py index 26c3e48365e06..7b65e9a809378 100644 --- a/mypy/types.py +++ b/mypy/types.py @@ -2420,9 +2420,7 @@ def __init__( if not isinstance(fallback.args[0], ProperType) or not isinstance( fallback.args[0], AnyType ): - fallback = fallback.copy_modified( - args=[AnyType(TypeOfAny.implementation_artifact)] - ) + fallback = fallback.copy_modified(args=[AnyType(TypeOfAny.special_form)]) self.partial_fallback = fallback self.items = items self.implicit = implicit From 25c13177b4e61545f1ae2a404be0daf77df45341 Mon Sep 17 00:00:00 2001 From: STerliakov Date: Wed, 5 Feb 2025 03:23:26 +0100 Subject: [PATCH 4/4] . --- mypy/messages.py | 1 - 1 file changed, 1 deletion(-) diff --git a/mypy/messages.py b/mypy/messages.py index 6b061a379ff64..3beb287bcc21c 100644 --- a/mypy/messages.py +++ b/mypy/messages.py @@ -2008,7 +2008,6 @@ def untyped_decorated_function(self, typ: Type, context: Context) -> None: if isinstance(typ, AnyType): self.fail("Function is untyped after decorator transformation", context) else: - breakpoint() self.fail( f'Type of decorated function contains type "Any" ({format_type(typ, self.options)})', context,