(🐞) `staticmethod` special-casing causes error to not be reported
オープン
まだ誰も着手していません。
bug
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
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
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
提供された例を再現し、mypy の staticmethod 専用の特別扱いと、コピーした typeshed の実装を比較する。デコレータと descriptor 型がどのように解析されるかを追跡する。完了条件は、Foo().copy() の場合と同様に、mypy が Foo().native() に対して missing-self エラーを報告することである。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- devtools
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 45/100