coverage report produces too many Anys
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
When generating a coverage report there are too many Anys reported for lines. I've figured out how it's counting Anys and I may be able to help with a patch.
To Reproduce
-
def test() -> str: value: str = getattr(test, '__name__') return value mypy --html-report . test.py- View generated
html/test.py.html
Expected Behavior
As mypy reported a success, I would expect no Anys, but maximally I would expect 1.
Actual Behavior
Mypy reports 4 explicit anys on the getattr line.
When stepping through the StatisticsVisitor visit I noticed this is because when visiting a call expression:
https://github.com/python/mypy/blob/d089891198ef470c8bec9bd7d7b50a02757c5b68/mypy/stats.py#L217-L225
- The call expression itself is processed, which first starts with the node itself. Because the result of
getattrisAnythe visitor hasAnyin itstypemapfor that node. This is arguably the onlyAnythat I would expect, and it probably should still not be reported because there is an explicit type on the assignment (I do note that assignment could be wrong, and maybe this should be reported as a partial cover). - The callee is then visited which will be processing the node with type
def (Any, name: builtins.str, Any =) -> Any, inStatisticsVisitor.typeit callsget_proper_types(collect_all_inner_types(t)) + [t]which is[Any, builtins.str, Any, Any, def (Any, name: builtins.str, Any =) -> Any]which will add 3 moreAnys to the line. Now that I'm looking at it closer, if I had addedAnys to the type definition oftestthey would increase the number ofAnys on the line when visiting the arguments togetattr.
Your Environment
- Mypy version used:
mypy 0.812 - Mypy command-line flags:
--html-report . - Mypy configuration options from
mypy.ini(and other config files): None - Python version used:
Python 3.8.8 - Operating system and version: N/A
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 da mypy/stats.py, esaminando la gestione delle espressioni di chiamata di StatisticsVisitor indicata nel report, quindi riproduci il caso con mypy --html-report . test.py. Traccia il modo in cui i tipi della chiamata, del callee e degli argomenti contribuiscono al report di coverage HTML; il lavoro è completato quando l’esempio non conta più ripetutamente i tipi Any annidati e il totale riportato corrisponde al comportamento previsto.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- testing-qa, tooling
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100