python / python/cpython

Have inspect.getdoc follow the MRO when a method docstring is only one line.

未關閉
#94,470 4 則留言 1 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

stdlib type-feature
主要語言
Python
星號
77.2k
分支
36k
PR 合併指標
PR 指標待擷取

描述

Feature or enhancement

"Hot" on the heels of 3.5ish's https://github.com/python/cpython/issues/59787 comes another idea: An age old pattern we have in our codebase is for people to put """See base class.""" as the docstring on methods to appease lint tooling demanding a docstring on non-trivial methods. As a consequence code written this way doesn't trigger the inspect.getdoc() feature from #59787 and the help() text in a Notebook for such functions is the content-free oneliner instead of heading up the MRO chain.

I propose a new feature: If the docstring for a method exists but is <= 1 line, follow the MRO as if there were no docstring and return

f"{onelinedoc}:\n{mro_doc}" as the docstring. Do this recursively, but collapse duplicate docstrings gathered along the way so that you could wind up with [good]:

"""See base class:
Fill a hovercraft with eels of the chosen species.

Args:
  species: A set of allowed Eel types.
  count: float, a non-negative number of eels to add. Fractions are allowed.
"""

rather than this degenerate pattern in deep heirarchies that could otherwise result [bad]:

"""See base class:
See base class:
See base class:
Fill a hovercraft with ...
"""

Collapsing identical docstrings along the heirarchy in this case also works for the situation where they're all the same cut and pasted oneliner and nothing else.

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

從 inspect.getdoc 入口點和 issue 中提出的範例開始。判斷遞迴 MRO 查找應如何處理單行 docstring 和重複文字,然後確認產生的文件是否在沒有重複行的情況下保留所需的展開形式。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
python
領域
tooling
Issue 類型
功能
難度
5/5
預估耗時
一週以上
活躍度
停滯
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。