You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Crash on a class whose __call__ attribute is its own type, passed where a Callable is expected #22398
The class from #22361 also crashes mypy when it is passed where a Callable is expected. #22362 fixes the call in check_call and leaves this path: visit_instance looks up __call__ at mypy/subtypes.py:659, gets C back, and checks C against the Callable again at line 661. x: Callable[[], int] = C() crashes the same way.
Traceback
case.py:8: 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: 2.5.0+dev
...
File "mypy/checkexpr.py", line 2912, in check_argelifnot is_subtype(caller_type, callee_type, options=self.chk.options):
File "mypy/subtypes.py", line 196, in is_subtype
File "mypy/subtypes.py", line 383, in _is_subtype
File "mypy/types.py", line 1719, in accept
File "mypy/subtypes.py", line 661, in visit_instancereturnself._is_subtype(call, right)
File "mypy/subtypes.py", line 455, in _is_subtype
File "mypy/subtypes.py", line 196, in is_subtype
... (the five frames above repeat)
File "mypy/expandtype.py", line 192, in __init__super().__init__()
RecursionError: maximum recursion depth exceeded
$ mypy --show-traceback case.py # master 5dc2840, pure Python
(the traceback above), exit 2
$ mypy case.py # mypy 2.4.0, compiled wheel
exit 139, no output
With def __call__(self) -> "C": ... in place of the attribute, mypy reports Argument 1 to "h" has incompatible type "C"; expected "Callable[[], int]" and does not crash. I'd expect the attribute form to give that error too.
Your Environment
Mypy version used: master 5dc2840 (2.5.0+dev), and 2.4.0 compiled
Mypy command-line flags: --show-traceback
Mypy configuration options from mypy.ini (and other config files): none
Python version used: 3.12.12
Operating system and version: macOS 26.7.2
Not checked: the C | None and Self variants on this path.
I'd keep #22362 as it is and guard visit_instance in its own change, since this loop never reaches check_call. Would a PR for that be welcome?
Activity
ilevkivskyi commentedon Nov 8, 2026
This is essentially a duplicate of #22361