Skip to content

Crash when checking for method override #2372

Closed
@ddfisher

Description

@ddfisher
class A:
    def f(self):
        # type: () -> str
        return 'foo'

class B(A):
    def f(self):
        # type: () -> str
        return self.x

    def initialize(self):
        # type: () -> None
        self.x = 'bar'

crashes with

/Users/ddfisher/test/test.py:7: error: INTERNAL ERROR -- please report a bug at https://github.com/python/mypy/issues
Traceback (most recent call last):
  File "/usr/local/Cellar/python3/3.5.2_1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/runpy.py", line 184, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/local/Cellar/python3/3.5.2_1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/Users/ddfisher/src/mypy/mypy/__main__.py", line 5, in <module>
    main(None)
  File "/Users/ddfisher/src/mypy/mypy/main.py", line 41, in main
    res = type_check_only(sources, bin_dir, options)
  File "/Users/ddfisher/src/mypy/mypy/main.py", line 86, in type_check_only
    options=options)
  File "/Users/ddfisher/src/mypy/mypy/build.py", line 180, in build
    dispatch(sources, manager)
  File "/Users/ddfisher/src/mypy/mypy/build.py", line 1509, in dispatch
    process_graph(graph, manager)
  File "/Users/ddfisher/src/mypy/mypy/build.py", line 1689, in process_graph
    process_stale_scc(graph, scc)
  File "/Users/ddfisher/src/mypy/mypy/build.py", line 1773, in process_stale_scc
    if graph[id].type_check_second_pass():
  File "/Users/ddfisher/src/mypy/mypy/build.py", line 1443, in type_check_second_pass
    return self.type_checker.check_second_pass()
  File "/Users/ddfisher/src/mypy/mypy/checker.py", line 211, in check_second_pass
    self.accept(node)
  File "/Users/ddfisher/src/mypy/mypy/checker.py", line 237, in accept
    typ = node.accept(self)
  File "/Users/ddfisher/src/mypy/mypy/nodes.py", line 531, in accept
    return visitor.visit_func_def(self)
  File "/Users/ddfisher/src/mypy/mypy/checker.py", line 451, in visit_func_def
    self.check_method_override(defn)
  File "/Users/ddfisher/src/mypy/mypy/checker.py", line 852, in check_method_override
    self.check_method_or_accessor_override_for_base(defn, base)
  File "/Users/ddfisher/src/mypy/mypy/checker.py", line 861, in check_method_or_accessor_override_for_base
    self.check_method_override_for_base_with_name(defn, name, base)
  File "/Users/ddfisher/src/mypy/mypy/checker.py", line 879, in check_method_override_for_base_with_name
    typ = bind_self(self.function_type(defn), self.class_context[-1])
IndexError: list index out of range

@elazarg @JukkaL I think this is also related to #2193.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions