Within Annotated[T, x], type errors in x are completely ignored
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 20.6k
- Forks
- 3.3k
- Métricas de merge de PR
- Métricas de PR pendientes
Descripción
Bug Report
mypy ignores the x expression in Annotated[T, x] without type-checking it. Although x has no effect on the typing interpretation of T, the expression x is still code that’s going to be executed at runtime*, so mypy should type-check x (as a separate object) before ignoring it.
(* Although it might not be executed immediately if from __future__ import annotations is in effect, it will be executed when typing.get_type_hints is used, so it’s still important for mypy to check it.)
An example of a real subtle bug that was missed because of this is zulip/zulip#26710.
To Reproduce
from typing import Annotated
def f(p: Annotated[int, 2 + "oops"]) -> None:
pass
mypy Playground, Pyright playground
Expected Behavior
I expect a type error at 2 + "oops". (Pyright agrees.)
Actual Behavior
mypy finds no errors.
Your Environment
- Mypy version used: 1.5.1
- Mypy command-line flags:
--strict - Mypy configuration options from
mypy.ini(and other config files): none - Python version used: 3.11.4
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Empieza reproduciendo el ejemplo Annotated[int, 2 + "oops"] en Python 3.11 con --strict y, a continuación, sigue el tratamiento que hace mypy de los metadatos de Annotated. Se considera terminado cuando mypy informa de un error de tipo para la expresión de metadatos, manteniendo al mismo tiempo la interpretación de typing de int.
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
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 45/100