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

Complex inheritance generates INTERNAL ERROR #11556

Closed
epenet opened this issue Nov 14, 2021 · 1 comment · Fixed by #11561
Closed

Complex inheritance generates INTERNAL ERROR #11556

epenet opened this issue Nov 14, 2021 · 1 comment · Fixed by #11561
Labels

Comments

@epenet
Copy link

epenet commented Nov 14, 2021

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)
@A5rocks
Copy link
Contributor

A5rocks commented Nov 15, 2021

perhaps this is similar to #10134 and #5425 ?

Here's a simplified repro:

class BaseFlow:
    async_specific = int

class StandardFlow(BaseFlow):
    async_specific = str

class ExtendedFlow(StandardFlow):
    def async_specific(
        self,
        service_info: int,
    ) -> None:
        ...

97littleleaf11 pushed a commit that referenced this issue Nov 18, 2021
Now we can override attributes with methods.

Closes #10134
Closes #11556

Co-authored-by: Alex Waygood <[email protected]>
tushar-deepsource pushed a commit to DeepSourceCorp/mypy that referenced this issue Jan 20, 2022
…n#11561)

Now we can override attributes with methods.

Closes python#10134
Closes python#11556

Co-authored-by: Alex Waygood <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants