python / python/mypy

Odd error message when kwargs passed as **dict

Abierto
#5,382 17 comentarios 34 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

feature priority-0-high topic-calls topic-usability
Lenguaje dominante
Python
Estrellas
20.6k
Forks
3.3k
Métricas de merge de PR
Métricas de PR pendientes

Descripción

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

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza con el reproductor de ThreadPoolExecutor del issue y ejecútalo con mypy 0.620 para inspeccionar los diagnósticos reportados para **opts. Determina cómo se manejan los argumentos de palabra clave basados en diccionarios y qué debería identificar el error; se considera completado cuando el diagnóstico es preciso y menciona el argumento o valor relevante.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
python
Área
devtools
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Necesita aclaración
Aptitud para principiantes
25/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.