(🐞) Locally narrowed value used in a lambda parameter from an overloaded higher order function is analyzed twice with different types
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
from typing import overload, Callable
@overload
def f() -> None: ...
@overload
def f(fn: Callable[[], object]) -> None: ...
def f(fn: object=1) -> None: ...
x: object
assert isinstance(x, str)
y = x
f(lambda: reveal_type(x)) # Revealed type is "str", Revealed type is "object"
f(lambda: reveal_type(y)) # Revealed type is "str"
The lambda is analyzed twice, once with the local type of the variable, and once with the global type of the variable, duplicating all notes and error messages.
The second usage with y is only analyzed once because it does not have a narrowed type.
- Related #11953
Credit to @septatrix for unearthing this.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Führe zunächst die bereitgestellte Reproduktion für Overload und Lambda aus, entweder lokal oder im verlinkten Playground, und vergleiche die Diagnosen für x und y. Verfolge, wie der überladene Higher-Order-Aufruf das Lambda analysiert, und überprüfe, dass der eingegrenzte Fall von x eine Reihe offengelegter Typen und Meldungen erzeugt, während der Fall von y unverändert bleibt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- compilers
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 45/100