Skip to content

IndexError in property incompatible with supertype #16896

@andrey-popov

Description

@andrey-popov

Crash Report

Checking the following minimal example with mypy causes it to crash with an IndexError:

from typing import Callable


class Message:
    pass


Handler = Callable[[Message], None]
VecHandler = Callable[[list[Message]], None]


class Foo:
    @property
    def method(self) -> Callable[[int, Handler | VecHandler], None]:
        raise NotImplementedError


class Bar(Foo):
    @property
    def method(self) -> Callable[[int, Handler], None]:
        raise NotImplementedError

Traceback

tests/mypy.py:19: error: INTERNAL ERROR -- Please try using mypy master on GitHub:
https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build
Please report a bug at https://github.com/python/mypy/issues
version: 1.10.0+dev
Traceback (most recent call last):
  File "/home/docker-user/.local/bin/mypy", line 8, in <module>
    sys.exit(console_entry())
  File "/home/docker-user/.local/lib/python3.10/site-packages/mypy/__main__.py", line 15, in console_entry
    main()
  File "/home/docker-user/.local/lib/python3.10/site-packages/mypy/main.py", line 100, in main
    res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)
  File "/home/docker-user/.local/lib/python3.10/site-packages/mypy/main.py", line 182, in run_build
    res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
  File "/home/docker-user/.local/lib/python3.10/site-packages/mypy/build.py", line 192, in build
    result = _build(
  File "/home/docker-user/.local/lib/python3.10/site-packages/mypy/build.py", line 266, in _build
    graph = dispatch(sources, manager, stdout)
  File "/home/docker-user/.local/lib/python3.10/site-packages/mypy/build.py", line 2942, in dispatch
    process_graph(graph, manager)
  File "/home/docker-user/.local/lib/python3.10/site-packages/mypy/build.py", line 3340, in process_graph
    process_stale_scc(graph, scc, manager)
  File "/home/docker-user/.local/lib/python3.10/site-packages/mypy/build.py", line 3441, in process_stale_scc
    graph[id].type_check_first_pass()
  File "/home/docker-user/.local/lib/python3.10/site-packages/mypy/build.py", line 2310, in type_check_first_pass
    self.type_checker().check_first_pass()
  File "/home/docker-user/.local/lib/python3.10/site-packages/mypy/checker.py", line 481, in check_first_pass
    self.accept(d)
  File "/home/docker-user/.local/lib/python3.10/site-packages/mypy/checker.py", line 595, in accept
    stmt.accept(self)
  File "/home/docker-user/.local/lib/python3.10/site-packages/mypy/nodes.py", line 1142, in accept
    return visitor.visit_class_def(self)
  File "/home/docker-user/.local/lib/python3.10/site-packages/mypy/checker.py", line 2313, in visit_class_def
    self.accept(defn.defs)
  File "/home/docker-user/.local/lib/python3.10/site-packages/mypy/checker.py", line 595, in accept
    stmt.accept(self)
  File "/home/docker-user/.local/lib/python3.10/site-packages/mypy/nodes.py", line 1223, in accept
    return visitor.visit_block(self)
  File "/home/docker-user/.local/lib/python3.10/site-packages/mypy/checker.py", line 2775, in visit_block
    self.accept(s)
  File "/home/docker-user/.local/lib/python3.10/site-packages/mypy/checker.py", line 595, in accept
    stmt.accept(self)
  File "/home/docker-user/.local/lib/python3.10/site-packages/mypy/nodes.py", line 897, in accept
    return visitor.visit_decorator(self)
  File "/home/docker-user/.local/lib/python3.10/site-packages/mypy/checker.py", line 4891, in visit_decorator
    self.visit_decorator_inner(e)
  File "/home/docker-user/.local/lib/python3.10/site-packages/mypy/checker.py", line 4934, in visit_decorator_inner
    found_method_base_classes = self.check_method_override(e)
  File "/home/docker-user/.local/lib/python3.10/site-packages/mypy/checker.py", line 1906, in check_method_override
    result = self.check_method_or_accessor_override_for_base(defn, base)
  File "/home/docker-user/.local/lib/python3.10/site-packages/mypy/checker.py", line 1941, in check_method_or_accessor_override_for_base
    if self.check_method_override_for_base_with_name(defn, name, base):
  File "/home/docker-user/.local/lib/python3.10/site-packages/mypy/checker.py", line 2050, in check_method_override_for_base_with_name
    self.check_override(
  File "/home/docker-user/.local/lib/python3.10/site-packages/mypy/checker.py", line 2224, in check_override
    context: Context = node.arguments[i + len(override.bound_args)]
IndexError: list index out of range
tests/mypy.py:19: : note: use --pdb to drop into pdb

To Reproduce

Simply run

mypy tests/mypy.py

where the content of the file is included above. The crash is reported at the line of the second @property.

The expected behaviour is that mypy finishes without a crash and reports an incompatible return type in the subclass.

mypy works as expected if I remove both @property or remove the first parameter (int) from the signatures.

Your Environment

  • Mypy version used: master@517f5aee2
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: 3.10
  • Operating system and version: Debian GNU/Linux 11 (bullseye)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions