python / python/mypy

Linecount Report over counting

Offen
#17,807 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

bug
Vorherrschende Sprache
Python
Sterne
20.6k
Forks
3.3k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Reproduziere den Bericht mit test.py und .mypy.ini bei aktiviertem linecount_report. Lies mypy.report.LineCountReporter.visit_func_def und vergleiche dessen Behandlung mit mypy.checker.TypeChecker.check_func_def und check_for_missing_annotations. Als abgeschlossen gilt, dass teilweise annotierte Funktionen nicht als vollständig typisiert gezählt werden und das vorgesehene Flag- oder Kompatibilitätsverhalten geklärt ist.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
tooling
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
42/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.