From 23d1fc7b47810d05009039e4bbd4b94d929b629d Mon Sep 17 00:00:00 2001 From: Charlie Denton Date: Mon, 22 Jan 2024 11:14:03 +0000 Subject: [PATCH] Fix IndexError for custom queryset managers Sometimes Mypy crashes on this line with an IndexError. This change builds on the change in https://github.com/typeddjango/django-stubs/pull/1786 by making further use of the safer variable `typed_var`. `typed_var` will equal `manager_instance.args` if `manager_instance.args` is populated, but if it isn't it will have another sensible value we can use instead. Because that value should be populated, this prevents the crash. --- mypy_django_plugin/transformers/managers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mypy_django_plugin/transformers/managers.py b/mypy_django_plugin/transformers/managers.py index c1d0e9177..65320ddbd 100644 --- a/mypy_django_plugin/transformers/managers.py +++ b/mypy_django_plugin/transformers/managers.py @@ -135,7 +135,7 @@ def _process_dynamic_method( ): ret_type = _replace_type_var(ret_type, base_that_has_method.defn.type_vars[0].fullname, typed_var[0]) args_types = [ - _replace_type_var(arg_type, base_that_has_method.defn.type_vars[0].fullname, manager_instance.args[0]) + _replace_type_var(arg_type, base_that_has_method.defn.type_vars[0].fullname, typed_var[0]) for arg_type in args_types ] if base_that_has_method.self_type: