From c1ab3aece4637d3c93a2e341e453ad91a834a882 Mon Sep 17 00:00:00 2001 From: Jukka Lehtosalo Date: Mon, 9 Feb 2026 15:19:44 +0000 Subject: [PATCH] Fix crash in vec len() plugin Fixes #20755. --- mypy/plugins/default.py | 2 +- test-data/unit/check-vec.test | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/mypy/plugins/default.py b/mypy/plugins/default.py index 57909ce7c730..802339783612 100644 --- a/mypy/plugins/default.py +++ b/mypy/plugins/default.py @@ -217,7 +217,7 @@ def get_class_decorator_hook_2( def len_callback(ctx: FunctionContext) -> Type: """Infer a better return type for 'len'.""" - if len(ctx.arg_types) == 1: + if len(ctx.arg_types) == 1 and len(ctx.arg_types[0]) == 1: arg_type = ctx.arg_types[0][0] arg_type = get_proper_type(arg_type) if isinstance(arg_type, Instance) and arg_type.type.fullname == "librt.vecs.vec": diff --git a/test-data/unit/check-vec.test b/test-data/unit/check-vec.test index fc28bb48f629..18d05a472688 100644 --- a/test-data/unit/check-vec.test +++ b/test-data/unit/check-vec.test @@ -43,3 +43,7 @@ T = TypeVar("T") def bad_generic_func(v: vec[T]) -> None: ... # E: Invalid item type for "vec" [builtins fixtures/len.pyi] + +[case testLenNoArgs] +len() # E: Too few arguments for "len" +[builtins fixtures/len.pyi]