Don't require annotations of kwargs initialized to bool, float, int or string constants
Personne n'a encore pris cette issue.
- Langage dominant
- Python
- Étoiles
- 20.6k
- Forks
- 3.3k
- Métriques de merge des PR
- Métriques de PR en attente
Description
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 :-)
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par examiner la PR préliminaire #12918 et les exemples de l'issue d'annotations naturelles pour les arguments nommés initialisés avec des constantes bool, int, float et string. Suivez le comportement pertinent de l'inférence de types et vérifiez que les annotations inférées sont contrôlées pour garantir leur exactitude. Le travail est terminé lorsque ces cas satisfont disallow_untyped_defs sans annotations explicites, tandis que les valeurs par défaut invalides continuent de produire des erreurs.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- python
- Domaine
- compilers
- Type d'issue
- Fonctionnalité
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 35/100