Doctest ignores methods decorated with `functools.singledispatchmethod`
オープン
まだ誰も着手していません。
stdlib
type-bug
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 35.9k
- PR マージ指標
- PR 指標を取得中
説明
Bug report
Bug description:
Doctest does not recognize tests in the docstrings of methods decorated with functools.singledispatchmethod. There's 2 causes:
- It checks the dictionary of classes for functions and subclasses, thereby not invoking descriptors. https://github.com/python/cpython/blob/df4a2f5bd74fc582d99e6a82e070058d7765f44d/Lib/doctest.py#L1061-L1073
functools.singledispatchmethoddoes not callfunctools.update_wrapperon its instance, only on the wrapper function returned from its__get__method.
A similar issue for cached_property was fixed in #107996.
Example
# mwe.py
import functools
class Class:
@functools.singledispatchmethod
def singledispatchmethod(self, arg):
"""
>>> print(Class().singledispatchmethod(5))
foo
"""
return "foo"
def regularmethod(self, arg):
"""
>>> print(Class().regularmethod(5))
foo
"""
return "foo"
$ python3 -m doctest -v mwe.py
Trying:
print(Class().regularmethod(5))
Expecting:
foo
ok
2 items had no tests:
mwe
mwe.Class
1 item passed all tests:
1 test in mwe.Class.regularmethod
1 test in 3 items.
1 passed.
Test passed.
doctest only finds one doctest, where there should be two.
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PRs
- gh-129579
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
Lib/doctest.py の 1061-1073 行付近にあるクラス辞書の処理から始め、functools.singledispatchmethod と issue #107996 で参照されている cached_property の修正を調べてください。singledispatchmethod の例の docstring に対する回帰テストを追加し、doctest が両方のメソッドを検出することを確認してください。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- testing-qa
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 35/100