`singledispatchmethod` inspected signature incorrectly includes `self`
まだ誰も着手していません。
評価
調査の方向性
Lib/functools.py の979行付近を読み、singledispatchmethod.get がバインドされたメソッドをどのようにラップするかに注目してください。提供されている inspect.signature と sig.bind の再現を実行してください。バインドされたシグネチャから self が省かれ、メソッドの実際の引数を受け入れ、関連するテストが通れば完了です。
索引モデルが issue の本文から書いたものです。
説明
Bug report
Bug description:
The result of singledispatchmethod.__get__ is wrapped to imitate the underlying function, instead of the result of func.__get__. This leads to an incorrect signature being reported by inspect.signature, which includes the leading self argument, thus misleading introspection tools as to the real arguments the method accepts.
import inspect
from functools import singledispatchmethod
class A:
@singledispatchmethod
def a(self, arg):
pass
sig = inspect.signature(A().a)
# <Signature (self, arg)> but we expect <Signature (arg)>
sig.bind(None) # should be OK because `A().a(None)` is OK. Instead:
# TypeError: missing a required argument: 'arg'
# because the first argument is erroneously bound to `self`.
One way to fix this might be to edit https://github.com/python/cpython/blob/6258844c27e3b5a43816e7c559089a5fe0a47123/Lib/functools.py#L979 to read instead
update_wrapper(_method, self.func.__get__(obj, cls))
CPython versions tested on:
3.10, 3.12
Operating systems tested on:
Linux, Windows
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 36k
- 平均マージ
- 1日 9時間
- マージ済み PR(30日)
- 558
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
python/cpython のほかの issue
-
docs pending
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
stdlib type-feature
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
stdlib type-feature
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
build type-bug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
-
stdlib topic-email type-feature
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
似ている issue
-
link-check link-check:sphinx-theme
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
qgis/QGIS-Documentation#11275 ·
-
bug priority:normal ready-for-dev
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
OpenHands/extensions#626 · コメント 1 件 ·
-
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
CSCfi/sd-search-api#39 ·
-
難易度 1/5 1時間未満 初心者へのやさしさ 90/100