python / python/cpython

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

Abierto
#121,394 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

interpreter-core type-feature
Lenguaje dominante
Python
Estrellas
77.2k
Forks
35.9k
Métricas de merge de PR
Métricas de PR pendientes

Descripción

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?

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Reproduce la salida informada con help(A), help(A.init) y una clase B vacía. Rastrea dónde se generan la docstring del init integrado y la salida de clase de pydoc, y luego identifica el área relevante de las pruebas de regresión. Se considera terminado cuando la orientación engañosa se corrige o elimina de forma coherente y la salida de help queda cubierta por pruebas.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
python
Área
documentation
Tipo de issue
Nueva funcionalidad
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.