Mypyc runtime TypeError exceptions when you change inherited method to a staticmethod
Open
Nobody has claimed this yet.
bug
topic-mypyc
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
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
...
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the reproduction in checkers_minimax.py and run the documented mypyc command followed by the Python invocation. Trace mypyc's handling of the inherited classmethod overridden as a staticmethod; done means the compiled program runs without the reported TypeError and the regression is covered by an appropriate test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- compilers, devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100