--disallow-any-generics is allowing defaultdict[Any, ...]
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
(A clear and concise description of what the bug is.)
To Reproduce
this python file (I was working on advent of code, this is about as minimal as I could reproduce)
import collections
import re
PATTERN = re.compile('^([^ ]+ [^ ]+) bags contain (.*)$')
BAG_RE = re.compile(r'(\d+) ([^ ]+ [^ ]+)')
def compute(s: str) -> int:
parents = collections.defaultdict(list)
for line in s.splitlines():
match = PATTERN.match(line)
assert match
k = match[1]
targets = [(int(n), tp) for n, tp in BAG_RE.findall(match[2])]
for _, color in targets:
parents[color].append(k)
total_colors = set()
todo = parents['shiny gold']
while todo:
color = todo.pop()
if color not in total_colors:
total_colors.add(color)
todo.extend(parents[color])
reveal_type(parents)
return len(total_colors)
Run with mypy --disallow-any-generics t.py
Expected Behavior
I expect an error requiring me to annotate parents = collections.defaultdict(list) because mypy has not inferred the key type (though, I think it should be able to infer that it is str from the code)
Actual Behavior
$ mypy t.py --disallow-any-generics
t.py:26: note: Revealed type is 'collections.defaultdict[Any, builtins.list[builtins.str*]]'
Your Environment
- Mypy version used: 0.790
- Mypy command-line flags:
--disallow-any-generics - Mypy configuration options from
mypy.ini(and other config files): N/A - Python version used: 3.8.5
- Operating system and version: ubuntu 20.04
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 ejecutando mypy 0.790 con --disallow-any-generics sobre el reproductor en t.py e inspecciona el tipo defaultdict revelado. Sigue el tratamiento de collections.defaultdict(list) y la inferencia de tipos genéricos; se considera terminado cuando el comando informe del diagnóstico previsto o infiera el tipo de clave de forma coherente con el comportamiento esperado en el issue.
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
- Bastante claro
- Aptitud para principiantes
- 35/100