Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linecount Report over counting #17807

Open
sagarbadiyani opened this issue Sep 22, 2024 · 1 comment · May be fixed by #17809
Open

Linecount Report over counting #17807

sagarbadiyani opened this issue Sep 22, 2024 · 1 comment · May be fixed by #17809
Labels
bug mypy got something wrong

Comments

@sagarbadiyani
Copy link

sagarbadiyani commented Sep 22, 2024

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_defs flag 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
@sagarbadiyani sagarbadiyani added the bug mypy got something wrong label Sep 22, 2024
@sagarbadiyani sagarbadiyani linked a pull request Sep 22, 2024 that will close this issue
@sbadiyani-eightfold
Copy link

Requesting some traction on this issue
Tagging some of the active contributors I know: @JukkaL @hauntsaninja
Thank you 🙏🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants