Repository: python/mypy

Issue:
Complex inheritance generates INTERNAL ERROR
<!--
  Use this form only if mypy reports an "INTERNAL ERROR" and/or gives a traceback.
  Please include the traceback and all other messages below (use `mypy --show-traceback`).
-->

**Crash Report**

On HomeAssistant project, a complex flow is generating an INTERNAL ERROR when trying to add type hints.
https://github.com/home-assistant/core/pull/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**

```python
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**

<!-- Include as many relevant details about the environment you experienced the bug in -->

- 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)

<!--
You can freely edit this text, please remove all the lines
you believe are unnecessary.
-->



Discussion:
perhaps this is similar to https://github.com/python/mypy/issues/10134 and https://github.com/python/mypy/issues/5425 ?

Here's a simplified repro:
```py
class BaseFlow:
    async_specific = int

class StandardFlow(BaseFlow):
    async_specific = str

class ExtendedFlow(StandardFlow):
    def async_specific(
        self,
        service_info: int,
    ) -> None:
        ...
```

Resolving patch:
diff --git a/mypy/checker.py b/mypy/checker.py
--- a/mypy/checker.py
+++ b/mypy/checker.py
@@ -1536,6 +1536,16 @@ def check_method_override_for_base_with_name(
                     original_type = self.function_type(original_node)
                 elif isinstance(original_node, Decorator):
                     original_type = self.function_type(original_node.func)
+                elif isinstance(original_node, Var):
+                    # Super type can define method as an attribute.
+                    # See https://github.com/python/mypy/issues/10134
+
+                    # We also check that sometimes `original_node.type` is None.
+                    # This is the case when we use something like `__hash__ = None`.
+                    if original_node.type is not None:
+                        original_type = get_proper_type(original_node.type)
+                    else:
+                        original_type = NoneType()
                 else:
                     assert False, str(base_attr.node)
             if isinstance(original_node, (FuncDef, OverloadedFuncDef)):


Test patch:
diff --git a/test-data/unit/check-classes.test b/test-data/unit/check-classes.test
--- a/test-data/unit/check-classes.test
+++ b/test-data/unit/check-classes.test
@@ -114,6 +114,43 @@ class A:
 A().f = None # E: Cannot assign to a method
 
 
+[case testOverrideAttributeWithMethod]
+# This was crashing:
+# https://github.com/python/mypy/issues/10134
+from typing import Protocol
+
+class Base:
+    __hash__ = None
+
+class Derived(Base):
+    def __hash__(self) -> int:  # E: Signature of "__hash__" incompatible with supertype "Base"
+        pass
+
+# Correct:
+
+class CallableProtocol(Protocol):
+    def __call__(self, arg: int) -> int:
+        pass
+
+class CorrectBase:
+    attr: CallableProtocol
+
+class CorrectDerived(CorrectBase):
+    def attr(self, arg: int) -> int:
+        pass
+
+[case testOverrideMethodWithAttribute]
+# The reverse should not crash as well:
+from typing import Callable
+
+class Base:
+    def __hash__(self) -> int:
+        pass
+
+class Derived(Base):
+    __hash__ = 1  # E: Incompatible types in assignment (expression has type "int", base class "Base" defined the type as "Callable[[Base], int]")
+
+
 -- Attributes
 -- ----------