Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Docstrings use `Optional[T]` incorrectly

Aperta
#502 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

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

Direzione di ricerca

Inizia con l’esempio di docstring in src/handwritten/task.py e leggi l’issue collegata #209 sull’aggiunta dei type hints. Esamina i package docstrings per individuare i casi in cui Optional descrive un valore predefinito invece di un tipo nullable, quindi allinea la documentazione ai tipi effettivi dei parametri. Il lavoro è completato quando le annotazioni Optional errate sono corrette in modo coerente.

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

Descrizione

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.

Lingua principale
Python
Stelle
590
Fork
199
Merge medio
1g 18h
PR unite (30g)
12

Preparare l'ambiente

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.

Altre issue di ni/nidaqmx-python

Tutte le issue di ni/nidaqmx-python

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.