Skip to content

Mypyc runtime TypeError exceptions when you change inherited method to a staticmethod #19558

@CoolCat467

Description

@CoolCat467

Crash Report

Using mypyc to compile an ABC subclass with @classmethod and implement it in a subclass as @staticmethod leads to runtime type exceptions.

checkers_minimax.py

from abc import ABC


class State:
    """State object."""


class MinimaxWithTT(ABC):
    @classmethod
    def terminal(cls, state: State) -> bool:
        return False

    def alphabeta_transposition_table(
        self,
        state: State,
    ) -> None:
        print(f"Just before crash {type(state) = }")
        self.terminal(state)


class CheckersMinimax(MinimaxWithTT):
    @staticmethod
    def terminal(state: State) -> bool:
        return False


def run() -> None:
    mm = CheckersMinimax()
    mm.alphabeta_transposition_table(State())


if __name__ == "__main__":
    run()
mypyc checkers_minimax.py
python -c "from checkers_minimax import run; run()"

Traceback

Traceback (most recent call last):
  File "<string>", line 1, in <module>
    from checkers_minimax import run; run()
                                      ~~~^^
  File "checkers_minimax.py", line 29, in run
    mm.alphabeta_transposition_table(State())
  File "checkers_minimax.py", line 18, in alphabeta_transposition_table
    self.terminal(state)
TypeError: checkers_minimax.State object expected; got abc.ABCMeta

To Reproduce

See above

Your Environment

  • Mypy version used: mypy 1.17.1 (compiled: yes)
  • Mypy command-line flags: See above
  • Mypy configuration options from mypy.ini (and other config files): None
  • Python version used: Python 3.13.3 (main, Jun 16 2025, 18:15:32) [GCC 14.2.0] on linux
  • Operating system and version:
> uname -a
Linux ideapad 6.14.0-24-generic #24-Ubuntu SMP PREEMPT_DYNAMIC Sun Jun 15 11:18:07 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
  • GCC version
> x86_64-linux-gnu-gcc --version
x86_64-linux-gnu-gcc (Ubuntu 14.2.0-19ubuntu2) 14.2.0
...

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-mypycmypyc bugs

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions