python / python/mypy

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

Offen
#17,200 0 Kommentare 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

feature
Vorherrschende Sprache
Python
Sterne
20.6k
Forks
3.3k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

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.)

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne damit, den Einstiegspunkt von stubgen und die Verarbeitung von --include-docstrings und --typeshed nachzuverfolgen. Vergleiche die generierte Ausgabe für ein stdlib-Paket wie builtins mit den entsprechenden typeshed-Annotationen und Docstrings. Als erledigt gilt ein dokumentierter Ansatz oder eine Implementierung, die die typeshed-Syntax mit generierten Docstrings kombiniert.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
tooling
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.