Skip to content

Commit c8c9d57

Browse files
authored
Fix crash in vec len() plugin (#20774)
Fixes #20755.
1 parent 2955e3c commit c8c9d57

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

mypy/plugins/default.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ def get_class_decorator_hook_2(
217217

218218
def len_callback(ctx: FunctionContext) -> Type:
219219
"""Infer a better return type for 'len'."""
220-
if len(ctx.arg_types) == 1:
220+
if len(ctx.arg_types) == 1 and len(ctx.arg_types[0]) == 1:
221221
arg_type = ctx.arg_types[0][0]
222222
arg_type = get_proper_type(arg_type)
223223
if isinstance(arg_type, Instance) and arg_type.type.fullname == "librt.vecs.vec":

test-data/unit/check-vec.test

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,7 @@ T = TypeVar("T")
4343

4444
def bad_generic_func(v: vec[T]) -> None: ... # E: Invalid item type for "vec"
4545
[builtins fixtures/len.pyi]
46+
47+
[case testLenNoArgs]
48+
len() # E: Too few arguments for "len"
49+
[builtins fixtures/len.pyi]

0 commit comments

Comments
 (0)