python / python/mypy

`mypy --any-exprs-report` depends on formatting

Offen
#18,405 0 Kommentare 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 report any-exprs.txt generated by mypy --any-exprs-report changes its output, even if the AST has not changed in any way.

To Reproduce

This is a minimal example:

Error = (
    int
    | int
)

mypy reports

 Name   Anys   Exprs   Coverage
-------------------------------
    t      2       4     50.00%
-------------------------------
Total      2       4     50.00%

On the other hand, this example produces no errors

OK = int | int

Again the table, for completeness.

 Name   Anys   Exprs   Coverage
-------------------------------
    s      0       2    100.00%
-------------------------------
Total      0       2    100.00%

The underlying reason is that mypy counts expressions set as TYPE_UNANALYZED as Anys expression. This is very surprising to me. The specific expression is assigned TYPE_UNANALYZED in StatisticsVisitor.type.

Expected Behavior

The invocation mypy --any-exprs-report matches the number of errors encountered by running mypy --disallow-any-exprs. Or at the very least clear up the documentation:

Causes mypy to generate a text file report documenting how many
    expressions of type ``Any`` are present within your codebase.

Your Environment

I don't think this matters, but:

  • Mypy version used:
    mypy 1.14.0 (compiled: yes)
    mypy 1.15.0+dev.d79d89e3ff31ed67a41b0663da9ec8e037d41fa0 (compiled: no)
  • Mypy command-line flags: --any-exprs-report
  • Mypy configuration options from mypy.ini (and other config files): None
  • Python version used: 3.12.1

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

Beginne mit der Implementierung des any-exprs-Reports und der im Report genannten Position StatisticsVisitor.type. Vergleiche die Behandlung von TYPE_UNANALYZED dort mit dem Verhalten von --disallow-any-exprs und prüfe anschließend die Formulierung in der Dokumentation zu --any-exprs-report. Erledigt ist die Aufgabe, wenn sich der Report bei äquivalenter Formatierung nicht mehr ändert oder das dokumentierte Verhalten genau beschreibt, was er zählt.

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
38/100

Neue Issues direkt in Ihr Postfach

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