Linecount Report over counting
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
The LineCountReporter (mypy.report.LineCountReporter) counts a function as typed even if one of the arguments is typed or it only has a return value (which I would refer as partially typed). Ideally, I would want a report of functions which are fully typed (and not partially) to gauge correctly how well-typed the codebase is.
To Reproduce
Create a python file test.py
from __future__ import annotations
def foo(a, b: str) -> str:
return "bar"
Create an ini file .mypy.ini
[mypy]
files = test.py
linecount_report = .
Now run mypy --config-file .mypy.ini
And cat linecount.txt
Expected Behavior
I would expect the line count report to look like
<don't care> <don't care> 0 1 total
Actual Behavior
<don't care> <don't care> 1 1 total
Your Environment
- Mypy version used: 1.12.0
- Mypy command-line flags: --config-file
- Mypy configuration options from
mypy.ini(and other config files):
[mypy]
files = test.py
linecount_report = .
- Python version used: 3.9.6
I believe this is happening because while visiting each function we are just checking for the existence of type attribute in its Function Definition
def visit_func_def(self, defn: FuncDef) -> None:
self.counts[defn.type is not None] += 1
I would expect this logic to be similar to the function def checker mypy.checker.TypeChecker.check_func_def; this method particularly mypy.checker.TypeChecker.check_for_missing_annotations which is actually a more elaborate check and goes over each argument to check the existence of its type
I am happy to raise a PR for this, but I need help with a couple of things
- Was this an intentional choice?
- If yes, can we consider adding a flag or reusing the
disallow_incomplete_defsflag for determining if the function should be counted as typed or not in the report - Even if no, this doesn't look like a backward compatible change, looking for thoughts around this
- One of the ways to not make this a breaking change would be to use a new flag which is specific to linecount, in which case, of course, this is a feature request and not a bug
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
Riproduci il report usando test.py e .mypy.ini con linecount_report abilitato. Leggi mypy.report.LineCountReporter.visit_func_def e confronta la sua gestione con mypy.checker.TypeChecker.check_func_def e check_for_missing_annotations. Il lavoro è completato quando le funzioni parzialmente annotate non vengono conteggiate come completamente tipizzate e il comportamento previsto del flag o della compatibilità è stato risolto.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- tooling
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 42/100