python / python/mypy

Covariance error inferred for lambda has invalid line number associated with it

Abierto
#8,592 3 comentarios 1 reacción 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

bug priority-0-high topic-error-reporting
Lenguaje dominante
Python
Estrellas
20.6k
Forks
3.3k
Métricas de merge de PR
Métricas de PR pendientes

Descripción

Versions

mypy 0.770
python 3.8.2

Description

This is probably related to the https://github.com/python/mypy/issues/4270

Problem is triggered when using recipe everything_except from hypothesis documentation:

https://hypothesis.readthedocs.io/en/latest/data.html#hypothesis.strategies.from_type

I have a file with following content (this is the whole file):

from typing import TypeVar

from hypothesis import strategies as st

_Ex = TypeVar("_Ex", covariant=True)


def everything_except(*types: type) -> st.SearchStrategy[_Ex]:
    strategy = st.from_type(type).flatmap(st.from_type)

    return strategy.filter(lambda x: not isinstance(x, types))  # type: ignore

Running mypy on first clean run (without .mypy_cache) has the following output:

example.py:1276: error: Cannot use a covariant type variable as a parameter
Found 1 error in 1 file (checked 1 source file)

For some reason, mypy sees error on line 1276 which does not exist. On the other hand, running mypy for the second time gives:

Success: no issues found in 1 source file

What's more, when you have pretty set to True, first run gives:

Traceback (most recent call last):
  File "/home/krprzyby/.local/bin/mypy", line 8, in <module>
    sys.exit(console_entry())
  File "/home/krprzyby/.local/lib/python3.8/site-packages/mypy/__main__.py", line 8, in console_entry
    main(None, sys.stdout, sys.stderr)
  File "mypy/main.py", line 89, in main
  File "mypy/build.py", line 180, in build
  File "mypy/build.py", line 249, in _build
  File "mypy/build.py", line 2649, in dispatch
  File "mypy/build.py", line 2956, in process_graph
  File "mypy/build.py", line 3073, in process_stale_scc
  File "mypy/errors.py", line 476, in file_messages
  File "mypy/errors.py", line 449, in format_messages
IndexError: list index out of range

Running mypy for the second time works correctly with pretty set to True because the line number is correct and # type: ignore works.

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

Reproduce el ejemplo proporcionado con un .mypy_cache vacío y la salida pretty habilitada. Empieza leyendo mypy/errors.py y las rutas de build.py relacionadas que aparecen en el traceback; se considera terminado cuando la primera ejecución informa de una línea de código fuente válida y no genera IndexError, mientras que el comportamiento de type-ignore se mantiene coherente en las ejecuciones posteriores.

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

Evaluación

Stack tecnológico
python
Área
compilers
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Bien especificado
Aptitud para principiantes
45/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.