Errors for union of callables could be better
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
Given this definition (playground):
f: Callable[[int, int], None] | Callable[[int, str], None]
this code results in the following errors:
f(5, 42) # E: Argument 2 has incompatible type "int"; expected "str" [arg-type]
f(5, '42') # E: Argument 2 has incompatible type "str"; expected "int" [arg-type]
Looking at the errors (which are probably emitted in a for-loop) one would miss the big picture, which is that it's a union of two incompatible types.
Perhaps we could "meet" the callables, thus resulting in:
f(5, 42) # E: Argument 2 has incompatible type "int"; expected <nothing> [arg-type]
f(5, '42') # E: Argument 2 has incompatible type "str"; expected <nothing> [arg-type]
Notably we handle defaults well, i.e. in this code:
class FInt:
def __call__(self, a: int, b: int=42) -> None:
return
class FStr:
def __call__(self, a: int, b: str='42') -> None:
return
f: FInt | FStr
we get
f(5, 42) # E: Argument 2 to "__call__" of "FStr" has incompatible type "int"; expected "str" [arg-type]
f(5, '42') # E: Argument 2 to "__call__" of "FInt" has incompatible type "str"; expected "int" [arg-type]
but no error on
f(5)
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
Comienza con los dos ejemplos enlazados de mypy playground y compara los diagnósticos para uniones de tipos invocables, incluido el caso con argumento predeterminado. Traza la ruta de comprobación de argumentos de los Callables que produce los errores indicados. El trabajo estará terminado cuando los diagnósticos comuniquen que no se pueden satisfacer firmas de Callable incompatibles, preservando al mismo tiempo el comportamiento válido del argumento predeterminado.
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
- 5/5
- Tiempo estimado
- Más de una semana
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100