python / python/mypy

stubgen: combine `--include-docstrings` and typeshed

Aperta
#17,200 0 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

feature
Lingua principale
Python
Stelle
20.6k
Fork
3.3k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

Feature

Run stubgen --include-docstrings -p $STDLIB_PACKAGE --typeshed (?) or some other way and have it generate a stub that has the same syntax as the typeshed with docstrings included.

Pitch

Right now, stubgen --include-docstrings -p builtins generates

…
class str:
    …
    def strip(self, *args, **kwargs):
        """Return a copy of the string with leading and trailing whitespace removed.

        If chars is given and not None, remove characters in chars instead."""
    …

whereas using the typeshed annotations it might instead look like

class str(Sequence[str]):
    …
    @overload
    def strip(self: LiteralString, chars: LiteralString | None = None, /) -> LiteralString:
        """Return a copy of the string with leading and trailing whitespace removed.

        If chars is given and not None, remove characters in chars instead."""

    @overload
    def strip(self, chars: str | None = None, /) -> str:  # type: ignore[misc]
        """Return a copy of the string with leading and trailing whitespace removed.

        If chars is given and not None, remove characters in chars instead."""
…

Apologies
I'm new to the mypy project, so please feel to close this if it is out of scope or if I have misunderstood your aim with stubgen. My particular use case is using this in pyright to get proper stdlib stub docstrings; it imports these from typeshed whose stubs don't include docstrings. (See typeshed discussion here.)

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 tracciando il punto di ingresso di stubgen e il modo in cui gestisce --include-docstrings e --typeshed. Confronta l’output generato per un pacchetto stdlib come builtins con le annotazioni e i docstring corrispondenti di typeshed. Il lavoro è completo quando esiste un approccio documentato o un’implementazione che combini la sintassi di typeshed con docstring generati.

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

Valutazione

Stack tecnologico
python
Ambito
tooling
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
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.