python / python/cpython

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

Aperta
#121,394 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

interpreter-core type-feature
Lingua principale
Python
Stelle
77.2k
Fork
35.9k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

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?

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Riproduci l'output segnalato con help(A), help(A.init) e una classe B vuota. Traccia dove vengono generati la docstring del init incorporato e l'output della classe pydoc, quindi individua l'area rilevante dei test di regressione. Il lavoro è completato quando le indicazioni fuorvianti sono corrette o rimosse in modo coerente e l'output di help è coperto dai test.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
documentation
Tipo di issue
Funzionalità
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.