Linecount Report over counting
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the report using test.py and .mypy.ini with linecount_report enabled. Read mypy.report.LineCountReporter.visit_func_def and compare its handling with mypy.checker.TypeChecker.check_func_def and check_for_missing_annotations. Done means partially annotated functions are not counted as fully typed, with the intended flag or compatibility behavior resolved.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100