pydoc output control for doctest cases
未关闭
还没有人认领这个 Issue。
stdlib
type-feature
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 36k
- PR 合并指标
- PR 指标待抓取
描述
Feature or enhancement
#File: pydoc_end_demo.py
"""
I very much appreciate both the doctest and the pydoc features of python for small developement
tasks with minimum overhead.
A slight enhancement to pydoc as proposed in this example would further increase the usefulness.
"""
def rotated( sequence, distance=1 ): # example to demonstrate the <pydoc-end> proposal
""" Returns sequence rotated by distance number of elements.
Examples: # small number of test cases (to be included in the pydoc output) show the use of the function
>>> rotated( ( "one", "two", "three", "four" ) )
('four', 'one', 'two', 'three')
>>> rotated( [ 2, 3, 5, 7, 11, 13 ], 2 )
[11, 13, 2, 3, 5, 7]
>>> rotated( "abcdefgh", -3 )
'defghabc'
<pydoc-end> # the proposed indicator string instructs pydoc to stop ouput here ((for this docstring))
Doctests: # exhaustive number of further test cases - not relevant for the api user
# but needed for test quality - without the proposal the test cases clutter the pydoc output
>>> rotated( "abcde", 0 )
'abcde'
>>> rotated( "abcde", 5 ) # abs(distance) == len(sequence)
'abcde'
>>> rotated( "abcde", -5 )
'abcde'
>>> rotated( "abcde", 6 ) # abs(distance) > len(sequence)
'eabcd'
>>> rotated( "abcde", -6 )
'bcdea'
>>> rotated( "", 5 ) # empty sequence
''
>>> rotated( [], -3 )
[]
"""
length = len(sequence)
if length == 0: return sequence
dist = distance % length
return sequence[-dist:] + sequence[:-dist]
if __name__ == "__main__":
# run the doctest cases:
print( ">>> doctest >>>" )
import doctest
doctest.testmod()
print( "<<< doctest <<<" )
Pitch
extensive doctest cases will no more clutter pydoc output: A single source file is sufficient for concise user docu as well as for comprehensive doctest cases.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先检查 pydoc_end_demo.py 中提议的行为,以及 pydoc 和 doctest 入口点目前如何处理 docstring。确定提议的 标记与 doctest 用例之间预期的交互,然后添加覆盖,证明简洁的文档仍然可见,同时后续示例仍然可测试。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- documentation
- Issue 类型
- 功能
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100