GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Segfault / RecursionError when calling an instance whose class declares __call__ as an attribute of its own type · Issue #22361 · python/mypy

Segfault / RecursionError when calling an instance whose class declares __call__ as an attribute of its own type #22361

New issue
Copy link
New issue
Copy link
Open
Open
Segfault / RecursionError when calling an instance whose class declares __call__ as an attribute of its own type#22361
Copy link
Labels
crashtopic-recursive-types

Description

@Choco-princess
Choco-princess
opened on Nov 3, 2026
Issue body actions

Crash Report

mypy crashes when an instance is called and its class declares __call__ as an attribute annotated with the class itself, a Self union, or C | None. Declaring the class is fine. The crash happens on the call expression. Compiled wheels segfault, and a pure-Python build raises RecursionError.

Possibly related to the closed callable-protocol-with-Self crashes (#17314, #16877), though those used protocols with a __call__ method.

Traceback

On master (pure Python):

case.py:5: error: INTERNAL ERROR -- Please try using mypy master on GitHub:
...
  File ".../mypy/expandtype.py", line 654, in expand_self_type
    return expand_type(typ, {var.info.self_type.id: replacement})
  File ".../mypy/expandtype.py", line 74, in expand_type
    return typ.accept(ExpandTypeVisitor(env, normalize_callables))
RecursionError: maximum recursion depth exceeded

Compiled wheels (2.4.0, 2.4.1) print no traceback and exit with Segmentation fault (exit code 139).

To Reproduce

class C:
    __call__: "C"

def f(x: C) -> None:
    x()

Run: mypy --python-version 3.13 --no-incremental case.py

Also crashes with __call__: "C | None", and with from typing import Self plus __call__: Self | None.

mypy-play: https://mypy-play.net/?gist=e7b53eb68b638455a3bac9a39f9f0a79

Expected Behavior

No crash. Either an error about the call or accepting it would be better than a crash.

Your Environment

  • Mypy version used: 2.4.0, 2.4.1 (compiled, segfault) and master 2.5.0+dev.623bef9 (RecursionError)

  • Mypy command-line flags: --python-version 3.13 --no-incremental

  • Mypy configuration options from mypy.ini (and other config files): none

  • Python version used: 3.13.16

  • Operating system and version: Linux

Activity

  1. Choco-princess
    added
    crash
    on Nov 3, 2026
  2. A5rocks
    added
    topic-recursive-types
    on Nov 3, 2026
  3. ilevkivskyi
    marked Crash on a class whose __call__ attribute is its own type, passed where a Callable is expected #22398 as a duplicate of this issue on Nov 8, 2026
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

    crashtopic-recursive-types

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.