python / python/mypy

(🐞) `reveal_type` on a lambda parameter from an overloaded higher order function shows two results

Offen
#11,953 4 Kommentare 4 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

bug topic-overloads topic-reveal-type
Vorherrschende Sprache
Python
Sterne
20.6k
Forks
3.3k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

Here the type of value is an non-inferred int, and there is only one usage of reveal_type, yet mypy is outputting two results (one of which is incorrect)

reveal_locals() shows two entries for value, but one being None not Any.

from typing import overload, Callable

@overload
def bar() -> None: ...
@overload
def bar(fn: Callable[[int], object]) -> None: ...

def bar(fn: object=1) -> None: ...
    

bar(lambda value: reveal_type(value))
bar(lambda value: reveal_locals())
main.py:11: note: Revealed type is "Any"
main.py:11: note: Revealed type is "builtins.int"
main.py:12: note: Revealed local types are:
main.py:12: note:     value: None
main.py:12: note:     value: builtins.int
Success: no issues found in 1 source file

Without removing duplicate messages you get this:

test.py:12: note: Revealed local types are:
test.py:12: note:     value: None
test.py:12: note: Revealed local types are:
test.py:12: note:     value: builtings.int
  • Cause of #5879

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 das Beispiel der überladenen Funktion höherer Ordnung aus main.py und die für test.py gezeigte doppelte reveal_locals-Ausgabe. Verfolge zunächst, wie reveal_type und reveal_locals die beiden Lambda-Parametertypen behandeln, und überprüfe dann, dass eine Verwendung ein korrektes Ergebnis und keine doppelten Meldungen zu lokalen Typen erzeugt.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
compilers, devtools
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

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