(🐞) `staticmethod` special-casing causes error to not be reported
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 20.6k
- Fork
- 3.3k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
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
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Riprodurre l’esempio fornito e confrontare la gestione speciale specifica di staticmethod da parte di mypy con l’implementazione copiata di typeshed. Tracciare come vengono analizzati i decoratori e i tipi di descriptor; il lavoro è completato quando mypy segnala l’errore missing-self per Foo().native() così come fa per Foo().copy().
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- devtools
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 45/100