From 1ddd09da18c64fd3db7e19d76e064f8414f4f0f2 Mon Sep 17 00:00:00 2001 From: cyphercodes Date: Mon, 18 May 2026 06:31:15 +0300 Subject: [PATCH 1/2] Fix crash on empty Annotated type application Fixes #21471. --- mypy/exprtotype.py | 6 +++++- test-data/unit/check-annotated.test | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/mypy/exprtotype.py b/mypy/exprtotype.py index 5a22b9c3c759a..5cf88f1adc9c5 100644 --- a/mypy/exprtotype.py +++ b/mypy/exprtotype.py @@ -122,7 +122,11 @@ def expr_to_unanalyzed_type( else: base_fullname = expr.base.fullname - if base_fullname is not None and base_fullname in ANNOTATED_TYPE_NAMES: + if ( + base_fullname is not None + and base_fullname in ANNOTATED_TYPE_NAMES + and args + ): # TODO: this is not the optimal solution as we are basically getting rid # of the Annotation definition and only returning the type information, # losing all the annotations. diff --git a/test-data/unit/check-annotated.test b/test-data/unit/check-annotated.test index d4de3f7b5043f..03ae8906f1d32 100644 --- a/test-data/unit/check-annotated.test +++ b/test-data/unit/check-annotated.test @@ -41,6 +41,11 @@ x: Annotated[int] # E: Annotated[...] must have exactly one type argument and a reveal_type(x) # N: Revealed type is "Any" [builtins fixtures/tuple.pyi] +[case testAnnotatedBadEmptyTupleIndexInTypeApplication] +from typing_extensions import Annotated +list[Annotated[()]] # E: Annotated[...] must have exactly one type argument and at least one annotation +[builtins fixtures/list.pyi] + [case testAnnotatedNested0] from typing_extensions import Annotated x: Annotated[Annotated[int, ...], ...] From 9fb86c831ea64ac7e87a50b574a39ab49ce833b7 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 18 May 2026 03:34:06 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- mypy/exprtotype.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/mypy/exprtotype.py b/mypy/exprtotype.py index 5cf88f1adc9c5..1c9323be056dd 100644 --- a/mypy/exprtotype.py +++ b/mypy/exprtotype.py @@ -122,11 +122,7 @@ def expr_to_unanalyzed_type( else: base_fullname = expr.base.fullname - if ( - base_fullname is not None - and base_fullname in ANNOTATED_TYPE_NAMES - and args - ): + if base_fullname is not None and base_fullname in ANNOTATED_TYPE_NAMES and args: # TODO: this is not the optimal solution as we are basically getting rid # of the Annotation definition and only returning the type information, # losing all the annotations.