python / python/mypy

bug inferring signatures from docstrings in stubgenc

Aperta
#11,092 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

bug topic-stubgen
Lingua principale
Python
Stelle
20.6k
Fork
3.3k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

Bug Report

When generating stubs from c modules, stubgen uses mypy.stubdoc to parse signatures from docstrings, if they are present, however, this does not work if the function takes no arguments

To Reproduce

Function with args:

>>> from mypy.stubdoc import infer_sig_from_docstring
>>> infer_sig_from_docstring('func(x) -> int', 'func')
[FunctionSig(name='func', args=[ArgSig(name='x', type=None, default=False)], ret_type='int')]

Function without args:

>>>: infer_sig_from_docstring('func() -> int', 'func')
[]  # <--- no signature!!!!

The fact that no signatures are returned means that the stubs that are generated look like this:

def func(*args, **kwargs) -> Any
    ...

But given that we have a docstring with a valid signature, the stubs should look like this:

def func() -> int
    ...

This seems like a bug. I'll make a PR to fix this when I have some time.

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

Inizia con mypy.stubdoc.infer_sig_from_docstring e riproduci i due esempi dell’issue, poi traccia il modo in cui stubgen usa le signature restituite. Il lavoro è completato quando una docstring senza argomenti come func() -> int produce una signature e stubgen genera il corrispondente stub di funzione tipizzato invece di un fallback *args/**kwargs.

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

Valutazione

Stack tecnologico
python
Ambito
devtools
Tipo di issue
Bug
Difficoltà
2/5
Tempo stimato
1-3 ore
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.