--disallow-any-generics is allowing defaultdict[Any, ...]
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 20.6k
- Fork
- 3.3k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
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
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia eseguendo mypy 0.790 con --disallow-any-generics sul riproduttore in t.py e ispeziona il tipo defaultdict rivelato. Segui la gestione di collections.defaultdict(list) e l’inferenza dei tipi generici; il lavoro è completato quando il comando riporta la diagnostica prevista oppure inferisce il tipo della chiave in modo coerente con il comportamento atteso nell’issue.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- devtools
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100