Skip to content

crash on decorated method redefinition + circular imports #1972

Closed
@dmoisset

Description

@dmoisset

Mypy crashes with an internal crash on this multi-file package. The example code doesn't make much sense (I arrived to it by trimming a much larger project that's crashing mypy), but I should probably just get errors. If I have the following three files:

# foo/__init__.py
from .derived import *

# foo/base.py
from . import *

class Base:
    @decorator
    def method(self) -> None:
        pass

# foo/derived.py
from .base import Base

class Derived(Base):
    def method(self) -> None:
        pass

And then I run mypy foo/base.py, I get the following

Traceback (most recent call last):
  File ".../bin/mypy", line 6, in <module>
    main(__file__)
  File ".../mypy/main.py", line 40, in main
    res = type_check_only(sources, bin_dir, options)
  File ".../mypy/main.py", line 81, in type_check_only
    options=options)
  File ".../mypy/build.py", line 177, in build
    dispatch(sources, manager)
  File ".../mypy/build.py", line 1323, in dispatch
    process_graph(graph, manager)
  File ".../mypy/build.py", line 1461, in process_graph
    process_stale_scc(graph, scc)
  File ".../mypy/build.py", line 1538, in process_stale_scc
    graph[id].type_check()
  File ".../mypy/build.py", line 1301, in type_check
    manager.type_checker.visit_file(self.tree, self.xpath)
  File ".../mypy/checker.py", line 152, in visit_file
    self.accept(d)
  File ".../mypy/checker.py", line 201, in accept
    typ = node.accept(self)
  File ".../mypy/nodes.py", line 660, in accept
    return visitor.visit_class_def(self)
  File ".../mypy/checker.py", line 802, in visit_class_def
    self.accept(defn.defs)
  File ".../mypy/checker.py", line 201, in accept
    typ = node.accept(self)
  File ".../mypy/nodes.py", line 723, in accept
    return visitor.visit_block(self)
  File ".../mypy/checker.py", line 897, in visit_block
    self.accept(s)
  File ".../mypy/checker.py", line 201, in accept
    typ = node.accept(self)
  File ".../mypy/nodes.py", line 475, in accept
    return visitor.visit_func_def(self)
  File ".../mypy/checker.py", line 325, in visit_func_def
    self.check_method_override(defn)
  File ".../mypy/checker.py", line 681, in check_method_override
    self.check_method_or_accessor_override_for_base(defn, base)
  File ".../mypy/checker.py", line 690, in check_method_or_accessor_override_for_base
    self.check_method_override_for_base_with_name(defn, name, base)
  File ".../mypy/checker.py", line 728, in check_method_override_for_base_with_name
    assert original_type is not None
AssertionError: 

*** INTERNAL ERROR ***

/home/machinalis/0/foo/derived.py:4: error: Internal error -- please report a bug at https://github.com/python/mypy/issues

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions