(🐞) Overload matching fails when sub expression contains an unrelated error
Offen
Dieses Issue hat noch niemand übernommen.
bug
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
from dataclasses import dataclass
from typing import Generic, _T as T, overload
@dataclass
class A(Generic[T]):
it: T
@overload
def foo(x: A[int]) -> int: ...
@overload
def foo(x: A[str]) -> str: ...
reveal_type(foo(A(str(1 + "")))) # int; expected str
I think that the solution would be to change the current logic in infer_overload_return_type to something like:
- infer the types of the argument expressions in the call site without the callabletype typecontext
- check each overload against the inferred types
- If the types of the expressions match the types of the arguments, then the overload is matched.
- check the call against the matching overload as normal to generate error messages
links ⛓
- super issue of #16025
- Related #16101
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
Beginne mit dem Lesen von infer_overload_return_type und reproduziere das bereitgestellte Beispiel, um zu beobachten, wie sich der Fehler bei einem unabhängigen Ausdruck auf die Überladungsauswahl auswirkt. Verfolge, wie Argumentausdrücke inferiert werden und wie jede Überladung geprüft wird. Die Aufgabe ist abgeschlossen, wenn das Beispiel str offenlegt und gleichzeitig die normale Fehlerberichterstattung für tatsächlich ungültige Aufrufe beibehält.
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