Doctest ignores methods decorated with `functools.singledispatchmethod`
未关闭
还没有人认领这个 Issue。
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 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 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