Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Complex inheritance generates INTERNAL ERROR #11556

Description

@epenet

Crash Report

On HomeAssistant project, a complex flow is generating an INTERNAL ERROR when trying to add type hints.
home-assistant/core#59503
I was able to reproduce the issue with a trimmed version of the code (see below).

Traceback

internal_error.py:36: 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: 0.920+dev.053a1beb94ee4e5b3260725594315d1b6776e42f
Traceback (most recent call last):
  File "/usr/local/bin/mypy", line 8, in <module>
    sys.exit(console_entry())
  File "/usr/local/lib/python3.8/dist-packages/mypy/__main__.py", line 11, in console_entry
    main(None, sys.stdout, sys.stderr)
  File "/usr/local/lib/python3.8/dist-packages/mypy/main.py", line 92, in main
    res, messages, blockers = run_build(sources, options, fscache, t0, stdout, stderr)
  File "/usr/local/lib/python3.8/dist-packages/mypy/main.py", line 170, in run_build
    res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
  File "/usr/local/lib/python3.8/dist-packages/mypy/build.py", line 180, in build
    result = _build(
  File "/usr/local/lib/python3.8/dist-packages/mypy/build.py", line 256, in _build
    graph = dispatch(sources, manager, stdout)
  File "/usr/local/lib/python3.8/dist-packages/mypy/build.py", line 2712, in dispatch
    process_graph(graph, manager)
  File "/usr/local/lib/python3.8/dist-packages/mypy/build.py", line 3043, in process_graph
    process_stale_scc(graph, scc, manager)
  File "/usr/local/lib/python3.8/dist-packages/mypy/build.py", line 3150, in process_stale_scc
    if not graph[id].type_check_second_pass():
  File "/usr/local/lib/python3.8/dist-packages/mypy/build.py", line 2197, in type_check_second_pass
    return self.type_checker().check_second_pass()
  File "/usr/local/lib/python3.8/dist-packages/mypy/checker.py", line 366, in check_second_pass
    self.check_partial(node)
  File "/usr/local/lib/python3.8/dist-packages/mypy/checker.py", line 377, in check_partial
    self.accept(node)
  File "/usr/local/lib/python3.8/dist-packages/mypy/checker.py", line 422, in accept
    stmt.accept(self)
  File "/usr/local/lib/python3.8/dist-packages/mypy/nodes.py", line 727, in accept
    return visitor.visit_func_def(self)
  File "/usr/local/lib/python3.8/dist-packages/mypy/checker.py", line 754, in visit_func_def
    self._visit_func_def(defn)
  File "/usr/local/lib/python3.8/dist-packages/mypy/checker.py", line 765, in _visit_func_def
    self.check_method_override(defn)
  File "/usr/local/lib/python3.8/dist-packages/mypy/checker.py", line 1451, in check_method_override
    if self.check_method_or_accessor_override_for_base(defn, base):
  File "/usr/local/lib/python3.8/dist-packages/mypy/checker.py", line 1479, in check_method_or_accessor_override_for_base
    if self.check_method_override_for_base_with_name(defn, name, base):
  File "/usr/local/lib/python3.8/dist-packages/mypy/checker.py", line 1540, in check_method_override_for_base_with_name
    assert False, str(base_attr.node)
AssertionError: Var(async_specific)
internal_error.py:36: : note: use --pdb to drop into pdb

To Reproduce

from typing import Any, Dict, TypedDict, cast

GenericServiceInfoType = Dict[str, Any]


class SpecificServiceInfo(TypedDict):
    host: str
    port: int


class BaseFlow:
    async def async_generic(
        self,
        service_info: GenericServiceInfoType,
    ) -> bool:
        return True

    async def async_specific(
        self,
        service_info: SpecificServiceInfo,
    ) -> bool:
        return await self.async_generic(cast(dict, service_info))


class StandardFlow(BaseFlow):
    async def async_standard_generic(
        self,
        service_info: GenericServiceInfoType,
    ) -> bool:
        return True

    async_specific = async_standard_generic  # type: ignore


class ExtendedFlow(StandardFlow):
    async def async_specific(
        self,
        service_info: SpecificServiceInfo,
    ) -> bool:
        return await self.async_generic(cast(dict, service_info))

Your Environment

  • Mypy version used: 0.920+dev.053a1beb94ee4e5b3260725594315d1b6776e42f
  • Mypy command-line flags:
  • Mypy configuration options from mypy.ini (and other config files):
  • Python version used: 3.8.10
  • Operating system and version: WSL (Ubuntu-20.04)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions