Add "is invariant" warning to Set as well as List for situations where a Collection should be used
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
Feature
mypy has a lovely warning about List being invariant in situations like this:
ls: List[int] = [1, 2, 3]
def process(stuff: List[Union[int, str]]):
...
process(ls) # type error here, w/ nice explanation of invariance and suggestion to use Sequence
However, it does not have the same warning when Set is used in the same way:
s: Set[int] = {1, 2, 3}
def process(stuff: Set[Union[int, str]]):
...
process(s) # merely states that the type is incompatible, no mention of invariance
Would be nice if the same warning mechanism could trigger here, suggesting Collection.
Pitch
Hopefully this is a simple widening of a rule that's special-cased for lists to get sets too? Not sure if other types like Dict/Tuple might be included too; I haven't tested them. If it's a lot of effort probably not worth it.
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 localizando la advertencia existente sobre la invariancia de List y sus pruebas; el issue no especifica archivos ni puntos de entrada concretos. Extiende el mismo comportamiento de advertencia a Set y verifica que el diagnóstico explique la invariancia y sugiera Collection, como se muestra en el ejemplo.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- tooling
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 45/100