Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

Docstrings use `Optional[T]` incorrectly

Abierto
#502 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
35/100
Tipo de issue
Documentación
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
python

Línea de trabajo

Comienza con el ejemplo de docstring en src/handwritten/task.py y lee el issue enlazado #209 sobre añadir type hints. Audita los package docstrings en busca de casos en los que Optional describa un valor predeterminado en lugar de un tipo nullable, y alinea la documentación con los tipos reales de los parámetros. Se considera terminado cuando las anotaciones Optional incorrectas se hayan corregido de forma coherente.

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

Descripción

Many of this package's docstrings incorrectly conflate Optional[T] with default arguments.
typing.Optional[T] means "either a T or a None", which is orthogonal to whether the parameter has a default argument or not.

Example: https://github.com/ni/nidaqmx-python/blob/master/src/handwritten/task.py

    def __init__(self, new_task_name='', *, grpc_options=None):
        """
        Creates a DAQmx task.

        Args:
            new_task_name (Optional[str]): Specifies the name to assign to
                the task.

                If you use this method in a loop and specify a name for the
                task, you must use the DAQmx Clear Task method within the loop
                after you are finished with the task. Otherwise, NI-DAQmx
                attempts to create multiple tasks with the same name, which
                results in an error.

            grpc_options (Optional[:class:`~nidaqmx.GrpcSessionOptions`]): Specifies
                the gRPC session options.
        """

new_task_name (Optional[str])): ... means that new_task_name has a type of typing.Optional[str], but that is not the case. It has a type of str. If you do not specify an argument for new_task_name, the default argument is used, which also has a type of str.

grpc_options (Optional[:class:~nidaqmx.GrpcSessionOptions]): ... is correct. The default argument has type None, so typing.Optional[GrpcSessionOptions] is needed to accept either a GrpcSessionOptions or a None.

https://www.sphinx-doc.org/en/master/usage/extensions/example_google.html uses the syntax param2 (:obj:int, optional): . I don't know which meaning of "optional" it's using.

The best way to fix this is to add type hints and delete the types from the docstrings.

Lenguaje dominante
Python
Estrellas
590
Forks
199
Merge medio
1 d 8 h
PR fusionados (30 d)
7

Preparar el entorno

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.

Más de ni/nidaqmx-python

Todos los issues de ni/nidaqmx-python

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.