classmethod decorator transforms callable into callable rather than producing a classmethod?
Offen
Dieses Issue hat noch niemand übernommen.
bug
topic-descriptors
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
At the point at which the decorator is applied, the class method isn't a callable yet. It's a classmethod object that replies to __get__ to produce the bound method. Yet, MyPy already thinks it's a callable:
from __future__ import annotations
from typing import Callable
def decorate(c: classmethod[None]) -> Callable[[X], None]:
def g(x: X) -> None:
return c.__func__(type(x))
return g
class X:
@decorate # error: Argument 1 to "decorate" has incompatible type "Callable[[Type[X]], None]"; expected "classmethod[None]"
@classmethod
def f(cls) -> None:
print("okay")
x = X()
x.f() # error: Invalid self argument "Type[X]" to class attribute function "f" with type "Callable[[X], None]"
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne damit, das bereitgestellte Beispiel mit mypy zu reproduzieren, und untersuche, wie der Checker gestapelte @decorate- und @classmethod-Decorator typisiert. Die Korrektur ist vollständig, wenn das Beispiel die an decorate übergebene classmethod und den späteren Aufruf x.f() ohne einen der beiden gemeldeten Fehler akzeptiert.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- devtools
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100