Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IndexError: tuple index out of range #1785

Closed
christianbundy opened this issue Oct 19, 2023 · 5 comments · Fixed by #1786
Closed

IndexError: tuple index out of range #1785

christianbundy opened this issue Oct 19, 2023 · 5 comments · Fixed by #1786
Labels
bug Something isn't working crash "Internal error" crashes from mypy mypy-plugin Issues specific to mypy_django_plugin

Comments

@christianbundy
Copy link
Contributor

Bug report

version: 1.6.1
Traceback (most recent call last):
  File "/.venv/bin/mypy", line 8, in <module>
    sys.exit(console_entry())
  File "/.venv/lib/python3.11/site-packages/mypy/__main__.py", line 15, in console_entry
    main()
  File "/.venv/lib/python3.11/site-packages/mypy/main.py", line 99, in main
    res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)
  File "/.venv/lib/python3.11/site-packages/mypy/main.py", line 178, in run_build
    res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
  File "/.venv/lib/python3.11/site-packages/mypy/build.py", line 189, in build
    result = _build(
  File "/.venv/lib/python3.11/site-packages/mypy/build.py", line 262, in _build
    graph = dispatch(sources, manager, stdout)
  File "/.venv/lib/python3.11/site-packages/mypy/build.py", line 2938, in dispatch
    process_graph(graph, manager)
  File "/.venv/lib/python3.11/site-packages/mypy/build.py", line 3336, in process_graph
    process_stale_scc(graph, scc, manager)
  File "/.venv/lib/python3.11/site-packages/mypy/build.py", line 3437, in process_stale_scc
    graph[id].type_check_first_pass()
  File "/.venv/lib/python3.11/site-packages/mypy/build.py", line 2306, in type_check_first_pass
    self.type_checker().check_first_pass()
  File "/.venv/lib/python3.11/site-packages/mypy/checker.py", line 475, in check_first_pass
    self.accept(d)
  File "/.venv/lib/python3.11/site-packages/mypy/checker.py", line 585, in accept
    stmt.accept(self)
  File "/.venv/lib/python3.11/site-packages/mypy/nodes.py", line 1145, in accept
    return visitor.visit_class_def(self)
  File "/.venv/lib/python3.11/site-packages/mypy/checker.py", line 2298, in visit_class_def
    self.accept(defn.defs)
  File "/.venv/lib/python3.11/site-packages/mypy/checker.py", line 585, in accept
    stmt.accept(self)
  File "/.venv/lib/python3.11/site-packages/mypy/nodes.py", line 1226, in accept
    return visitor.visit_block(self)
  File "/.venv/lib/python3.11/site-packages/mypy/checker.py", line 2754, in visit_block
    self.accept(s)
  File "/.venv/lib/python3.11/site-packages/mypy/checker.py", line 585, in accept
    stmt.accept(self)
  File "/.venv/lib/python3.11/site-packages/mypy/nodes.py", line 900, in accept
    return visitor.visit_decorator(self)
  File "/.venv/lib/python3.11/site-packages/mypy/checker.py", line 4773, in visit_decorator
    self.visit_decorator_inner(e)
  File "/.venv/lib/python3.11/site-packages/mypy/checker.py", line 4778, in visit_decorator_inner
    self.check_func_item(e.func, name=e.func.name, allow_empty=allow_empty)
  File "/.venv/lib/python3.11/site-packages/mypy/checker.py", line 1071, in check_func_item
    self.check_func_def(defn, typ, name, allow_empty)
  File "/.venv/lib/python3.11/site-packages/mypy/checker.py", line 1281, in check_func_def
    self.accept(item.body)
  File "/.venv/lib/python3.11/site-packages/mypy/checker.py", line 585, in accept
    stmt.accept(self)
  File "/.venv/lib/python3.11/site-packages/mypy/nodes.py", line 1226, in accept
    return visitor.visit_block(self)
  File "/.venv/lib/python3.11/site-packages/mypy/checker.py", line 2754, in visit_block
    self.accept(s)
  File "/.venv/lib/python3.11/site-packages/mypy/checker.py", line 585, in accept
    stmt.accept(self)
  File "/.venv/lib/python3.11/site-packages/mypy/nodes.py", line 1246, in accept
    return visitor.visit_expression_stmt(self)
  File "/.venv/lib/python3.11/site-packages/mypy/checker.py", line 4276, in visit_expression_stmt
    expr_type = self.expr_checker.accept(s.expr, allow_none_return=True, always_allow_any=True)
  File "/.venv/lib/python3.11/site-packages/mypy/checkexpr.py", line 5366, in accept
    typ = self.visit_call_expr(node, allow_none_return=True)
  File "/.venv/lib/python3.11/site-packages/mypy/checkexpr.py", line 452, in visit_call_expr
    return self.visit_call_expr_inner(e, allow_none_return=allow_none_return)
  File "/.venv/lib/python3.11/site-packages/mypy/checkexpr.py", line 538, in visit_call_expr_inner
    self.accept(e.callee, type_context, always_allow_any=True, is_callee=True)
  File "/.venv/lib/python3.11/site-packages/mypy/checkexpr.py", line 5374, in accept
    typ = node.accept(self)
          ^^^^^^^^^^^^^^^^^
  File "/.venv/lib/python3.11/site-packages/mypy/nodes.py", line 1831, in accept
    return visitor.visit_member_expr(self)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/.venv/lib/python3.11/site-packages/mypy/checkexpr.py", line 3161, in visit_member_expr
    result = self.analyze_ordinary_member_access(e, is_lvalue)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/.venv/lib/python3.11/site-packages/mypy/checkexpr.py", line 3182, in analyze_ordinary_member_access
    member_type = analyze_member_access(
                  ^^^^^^^^^^^^^^^^^^^^^^
  File "/.venv/lib/python3.11/site-packages/mypy/checkmember.py", line 201, in analyze_member_access
    result = _analyze_member_access(name, typ, mx, override_info)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/.venv/lib/python3.11/site-packages/mypy/checkmember.py", line 220, in _analyze_member_access
    return analyze_instance_member_access(name, typ, mx, override_info)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/.venv/lib/python3.11/site-packages/mypy/checkmember.py", line 349, in analyze_instance_member_access
    return analyze_member_var_access(name, typ, info, mx)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/.venv/lib/python3.11/site-packages/mypy/checkmember.py", line 534, in analyze_member_var_access
    return analyze_var(name, v, itype, info, mx, implicit=implicit)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/.venv/lib/python3.11/site-packages/mypy/checkmember.py", line 830, in analyze_var
    result = hook(
             ^^^^^
  File "/.venv/lib/python3.11/site-packages/mypy_django_plugin/transformers/managers.py", line 267, in resolve_manager_method
    return resolve_manager_method_from_instance(instance=ctx.type, method_name=method_name, ctx=ctx)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/.venv/lib/python3.11/site-packages/mypy_django_plugin/transformers/managers.py", line 241, in resolve_manager_method_from_instance
    method_type = get_method_type_from_dynamic_manager(api, method_name, instance)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/.venv/lib/python3.11/site-packages/mypy_django_plugin/transformers/managers.py", line 88, in get_method_type_from_dynamic_manager
    _process_dynamic_method(
  File "/.venv/lib/python3.11/site-packages/mypy_django_plugin/transformers/managers.py", line 129, in _process_dynamic_method
    ret_type, base_that_has_method.defn.type_vars[0].fullname, manager_instance.args[0]
                                                               ~~~~~~~~~~~~~~~~~~~~~^^^
IndexError: tuple index out of range

System information

  • OS: Docker python:3.11
  • python version: 3.11
  • django version: 4.2
  • mypy version: 1.6.1
  • django-stubs version: 4.2.5
@christianbundy christianbundy added the bug Something isn't working label Oct 19, 2023
@intgr
Copy link
Collaborator

intgr commented Oct 20, 2023

Do you have example code that reproduces this?

Is this a regression in 4.2.5 or does this affect earlier versions as well?

@intgr intgr added mypy-plugin Issues specific to mypy_django_plugin crash "Internal error" crashes from mypy labels Oct 20, 2023
@intgr
Copy link
Collaborator

intgr commented Oct 20, 2023

Looks like it might be related to #1666 from django-stubs 4.2.4.

@intgr
Copy link
Collaborator

intgr commented Oct 20, 2023

Ping @moranabadie.

@flaeppe
Copy link
Member

flaeppe commented Oct 20, 2023

A first step here might be to only resolve the crash. i.e. gracefully handle empty manager_instance.args (and perhaps also base_that_has_method.defn.type_vars). Then it might be possible to run again and get types to see what could be affected and/or incorrect.

Might be as simple as a typo that triggers the crash.

moranabadie added a commit to moranabadie/django-stubs that referenced this issue Oct 20, 2023
moranabadie added a commit to moranabadie/django-stubs that referenced this issue Oct 21, 2023
moranabadie added a commit to moranabadie/django-stubs that referenced this issue Oct 21, 2023
moranabadie added a commit to moranabadie/django-stubs that referenced this issue Oct 21, 2023
moranabadie added a commit to moranabadie/django-stubs that referenced this issue Oct 22, 2023
moranabadie added a commit to moranabadie/django-stubs that referenced this issue Oct 22, 2023
moranabadie added a commit to moranabadie/django-stubs that referenced this issue Oct 22, 2023
moranabadie added a commit to moranabadie/django-stubs that referenced this issue Oct 22, 2023
@christianbundy
Copy link
Contributor Author

christianbundy commented Oct 23, 2023

Sorry for the late comment here -- I don't have a minimal repro, but the code is roughly:

# related.py
class RelatedQuerySet(QuerySet["Related"]):
    def foo() -> None:
        ...

class RelatedManager(Manager["Related"]):
   ...

RelatedModelManager = RelatedManager.from_queryset(
    RelatedQuerySet
)

class Related(Model):
    objects = RelatedModelManager()
    my_model = ForeignKey("MyModel", related_name="related_objects")
# my_model.py
class MyModel(Model):
    @property
    def related_foo() -> None:
        return self.related_objects.foo(). # error happens here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working crash "Internal error" crashes from mypy mypy-plugin Issues specific to mypy_django_plugin
Development

Successfully merging a pull request may close this issue.

3 participants