(🐞) `staticmethod` special-casing causes error to not be reported
Offen
Dieses Issue hat noch niemand übernommen.
bug
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
If we copy the implementation of staticmethod from typeshed, mypy correctly reports the error here.
So it seems that mypys dedicated special-casing of staticmethod is causing this issue to be incorrectly not reported.
from collections.abc import Callable
from typing import Generic, ParamSpec, TypeVar, overload
P = ParamSpec("P")
T = TypeVar("T")
R_co = TypeVar("R_co", covariant=True)
def contextmanager(fn: Callable[P, R_co]) -> Callable[P, R_co]:
def func(*args: P.args, **kwargs: P.kwargs) -> R_co:
return fn(*args, **kwargs)
return func
class staticmethod_copy(Generic[P, R_co]):
@property
def __func__(self) -> Callable[P, R_co]: ...
@property
def __isabstractmethod__(self) -> bool: ...
def __init__(self, __f: Callable[P, R_co]) -> None: ...
@overload
def __get__(self, __instance: None, __owner: type) -> Callable[P, R_co]: ...
@overload
def __get__(self, __instance: T, __owner: type[T] | None = None) -> Callable[P, R_co]: ...
__name__: str
__qualname__: str
@property
def __wrapped__(self) -> Callable[P, R_co]: ...
def __call__(self, *args: P.args, **kwargs: P.kwargs) -> R_co: ...
# Just the relevant part of staticmethod definition that is needed
#class staticmethod(Generic[P, R_co]):
# def __init__(self, __f: Callable[P, R_co]) -> None: ...
# def __call__(self, *args: P.args, **kwargs: P.kwargs) -> R_co: ...
class Foo:
@contextmanager
@staticmethod_copy
def copy() -> None: ...
@contextmanager
@staticmethod
def native() -> None: ...
Foo().copy() # ✅ error: Attribute function "copy" with type "Callable[[], None]" does not accept self argument [misc]
Foo().native() # ❌no error
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
Das bereitgestellte Beispiel reproduzieren und die dedizierte Sonderbehandlung von staticmethod durch mypy mit der kopierten typeshed-Implementierung vergleichen. Nachverfolgen, wie die Decorators und Descriptor-Typen analysiert werden; abgeschlossen ist die Aufgabe, wenn mypy den missing-self-Fehler für Foo().native() ebenso meldet wie für Foo().copy().
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
- 45/100