python / python/mypy

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

Offen
#19,558 3 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

bug topic-mypyc
Vorherrschende Sprache
Python
Sterne
20.6k
Forks
3.3k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

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
...

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit der Reproduktion in checkers_minimax.py und führe den dokumentierten mypyc-Befehl gefolgt vom Python-Aufruf aus. Verfolge, wie mypyc die geerbte classmethod behandelt, die als staticmethod überschrieben wurde; abgeschlossen ist die Aufgabe, wenn das kompilierte Programm ohne den gemeldeten TypeError ausgeführt wird und die Regression durch einen geeigneten Test abgedeckt ist.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
compilers, devtools
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.