Don't require annotations of kwargs initialized to bool, float, int or string constants
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
See PR: #12918 (draft).
Feature
There should be no need for annotations for kwargs in the following (partial) function definitions:
def bool_args(ok=True, die=False)
def int_arg(i=1)
def float_arg(ratio=1.0)
def string_arg(s="Hello World")
In this example, the natural annotations are as follows:
def bool_args(ok: bool=True, die: bool=False): pass
def int_arg(i:int=1): pass
def float_arg(ratio: float=1.0): pass
def string_arg(s:str="Hello World"): pass
The issue proposes a non-trivial change to mypy's type inference. The proposal suggests that mypy act as if a natural annotation exists for an initialized kwarg. Note: mypy will (must!) check the new (natural) annotation, and mypy must complain if the natural annotation is not correct.
Pitch
At present, with disallow_untyped_defs = True and disallow_incomplete_defs = False, mypy complains that the signatures above lack annotations for the kinds of kwargs shown above. Such annotations unnecessarily clutter code. It should be possible to infer the types of the kwargs based on the obvious types of the constants!
This feature would fix my biggest gripe about mypy :-)
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit der Durchsicht des Entwurfs-PR #12918 und der Beispiele des Issues für natürliche Annotationen von Schlüsselwortargumenten, die mit bool-, int-, float- und String-Konstanten initialisiert werden. Vollziehe das relevante Verhalten der Typinferenz nach und verifiziere, dass die inferierten Annotationen auf Korrektheit geprüft werden. Als erledigt gilt die Aufgabe, wenn diese Fälle disallow_untyped_defs ohne explizite Annotationen erfüllen, während ungültige Standardwerte weiterhin Fehler erzeugen.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- compilers
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100