meet.is_overlapping_types should be more relaxed for isinstance checks
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Currently, the implementation of meet.is_overlapping_types(...) defaults to returning False when it encounters two unexpected types, and doesn't attempt to handle multiple inheritance at all. The current implementation also considers two types like List[A] and List[B] to be non-overlapping, even though they may overlap when both lists are empty.
This behavior makes sense when is_overlapping_types is used to detect unsafe overload variants, but may be too restrictive/cause branches to be unexpectedly unreachable when used for isinstance checks and if x is None checks and the like.
For more context, see https://github.com/python/mypy/pull/5476#discussion_r211030040 and https://github.com/python/mypy/issues/3603.
Some possible solutions include:
- Add a flag that makes
is_overlapping_typesdefault to returning True, not False. The main disadvantage here is that this would then makeis_overlapping_typesconsider two unrelated types likeType[A]andTypedDict[...]to be overlapping, which seems wrong. - Add a flag named
allow_multiple_inheritancewhich makes the "if left and right are Instances" case just always return True. The main disadvantage here is that this may not capture every edge case we want to relax.
It may also be the case that neither solutions work and a more careful rearrangement of is_overlapping_types is necessary. The existing implementation of is_overlapping_types is designed to rule out bad combinations/normalize all types to Instance whenever possible, which may or may not be the correct thing to do for reachability checks.
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 der Implementierung von meet.is_overlapping_types sowie der Diskussion in PR 5476 und issue 3603. Vergleiche das aktuelle Verhalten bei unerwarteten Typen, Mehrfachvererbung und List[A] gegenüber List[B], und bestimme anschließend, welches Erreichbarkeitsverhalten beabsichtigt ist. Erledigt ist die Aufgabe, wenn ein Ansatz festgelegt wurde, der die isinstance- und None-Prüfungen lockert, ohne die Prüfungen zur Sicherheit von Overloads fälschlicherweise auszuweiten.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- compilers
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Muss geklärt werden
- Anfängerfreundlichkeit
- 25/100