python / python/cpython

"See help(type(self)) for accurate signature" in `__init__`'s docstring is misleading

オープン
#121,394 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

interpreter-core type-feature
主要言語
Python
スター
77.2k
フォーク
35.9k
PR マージ指標
PR 指標を取得中

説明

Feature or enhancement

Let's say I have a simple class:

class A:
    def __init__(self, a):
        self.a = a

help(A) will produce:

Help on class A in module __main__:

class A(builtins.object)
 |  A(a)
 |
 |  Methods defined here:
 |
 |  __init__(self, a)
 |      Initialize self.  See help(type(self)) for accurate signature.
 |
 |  ----------------------------------------------------------------------
 |  Data descriptors defined here:
 |
 |  __dict__
 |      dictionary for instance variables
 |
 |  __weakref__
 |      list of weak references to the object

Note that the signature is already accurate. But, now I see this message: See help(type(self)) for accurate signature.. Let's try to do something about it.

Let's follow the instruction:

class A:
    def __init__(self, a):
        help(type(self))
        self.a = a

It will produce:

Help on class A in module __main__:

class A(builtins.object)
 |  A(a)
 |
 |  Methods defined here:
 |
 |  __init__(self, a)
 |      Initialize self.  See help(type(self)) for accurate signature.
 |
 |  ----------------------------------------------------------------------
 |  Data descriptors defined here:
 |
 |  __dict__
 |      dictionary for instance variables
 |
 |  __weakref__
 |      list of weak references to the object

Exactly the same signature. With exactly the same message.

Now, let's try a different example, an empty class:

class B: ...

help(B.__init__) will say:

Help on wrapper_descriptor:

__init__(self, /, *args, **kwargs) unbound builtins.object method
    Initialize self.  See help(type(self)) for accurate signature.

And help(B) will say (notice that there would be no __init__ at all):

Help on class B in module __main__:

class B(builtins.object)
 |  Data descriptors defined here:
 |
 |  __dict__
 |      dictionary for instance variables
 |
 |  __weakref__
 |      list of weak references to the object

Is this message See help(type(self)) for accurate signature really useful? When do users benefit from seeing it?

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

help(A)、help(A.init)、および空のクラス B を使って、報告された出力を再現します。組み込みの init の docstring と pydoc のクラス出力がどこで生成されるかを追跡し、関連する回帰テスト領域を特定します。誤解を招く案内が一貫して修正または削除され、help の出力がテストでカバーされれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
documentation
issue の種類
機能追加
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。