Odd error message when kwargs passed as **dict

Ouverte
#5,382 17 commentaires 35 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Évaluation

Difficulté
4/5
Temps estimé
3-5 jours
Accessibilité débutants
25/100
Type d'issue
Bug
Clarté
À clarifier
Activité
À l'abandon
Stack technique
python
Domaine
devtools

Piste de recherche

Commencez par le reproducteur ThreadPoolExecutor de l’issue et exécutez-le avec mypy 0.620 afin d’inspecter les diagnostics signalés pour **opts. Examinez le traitement des arguments nommés basés sur des dictionnaires et déterminez ce que l’erreur devrait identifier ; c’est terminé lorsque le diagnostic est exact et nomme l’argument ou la valeur concerné(e).

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

feature priority-0-high topic-calls topic-usability

Checking this with mypy 0.620:

from concurrent.futures import ThreadPoolExecutor
import sys

opts = {'max_workers': None}
if sys.version_info >= (3, 6):
    opts['thread_name_prefix'] = 'SyncWorker'
executor = ThreadPoolExecutor(**opts)

...yields:

mypy_bug.py:6: error: Incompatible types in assignment (expression has type "str", target has type "None")
mypy_bug.py:7: error: Argument 1 to "ThreadPoolExecutor" has incompatible type "**Dict[str, None]"; expected "str"

Let's ignore the first error for now. But the second seems to have an incorrect message, specifically I think the **Dict[str, None] in it is weird. Just guessing, is it trying to assign something to the ThreadPoolExecutor's thread_name_prefix arg which is a str? Maybe the None from max_workers because passing kwargs as a dict like this might result in random/varying order of the dict items? But if that's the case, I'd expect it to say something else than **Dict[str, None] as the culprit, maybe None or int, but not the whole **dict.

Another thought is that when kwargs is passed as **dicts like this, their order is not really defined, so "Argument 1" isn't very helpful. Would be better to say the argument's name.

But maybe I'm just all off track here -- will leave the rest to someone who actually has an informed opinion :)

Langage dominant
Python
Étoiles
20.6k
Forks
3.3k
Merge moyen
1 j 18 h
PR mergées (30 j)
54

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de python/mypy

Toutes les issues de python/mypy

Issues similaires

Plus d'issues Python

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.