Relax default overload subtyping checks
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Currently, mypy ensures monotnonically increasing order when testing overloads against overloads:
However, I believe (1) this rule does more harm than good in many cases when it is correct, and (2) there are many cases where it is incorrect. Therefore, I propose to move this check behind a new strictness flag and disable it by default. Later, one can see if the check can be refined to deal with the cases listed below.
Rationale
In https://github.com/python/typing/issues/2021 I showed that the current typing spec is too strict with respect to subtyping overloads.
When this check is incorrect
The check is incorrect when overloads are commutative, i.e. changing the overload order describes the same callable type. This is the case when:
-
Argument signatures are mutually exclusive mypy-playground
-
Argument types are mutually exclusive (e.g. via
@disjoint_bases) mypy-playground -
Argument types overlap, but return types are identical. mypy-playground
When this check is technically correct, but hurts in practice
As @disjoint_bases is relatively new, many libraries likely do not use it. Moreover, Intersection types are still not supported. Thus, many classes that are compatible at runtime cannot be put under the umbrella of a shared Protocol because inadvertently they will use different overload order at one point or another.
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 in mypy/subtypes.py bei den Zeilen 1003-1009 und untersuche, wie Overloads gegen Overloads geprüft werden. Lies die verlinkte typing-Diskussion und die Beispiele durch, ermittle anschließend das Verhalten des Strictness-Flags und verifiziere, dass die Prüfung standardmäßig deaktiviert ist, aber unter dem Flag weiterhin verfügbar bleibt.
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
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100