Relax default overload subtyping checks
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 20.6k
- Fork
- 3.3k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
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.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia in mypy/subtypes.py alle righe 1003-1009 e analizza come vengono verificati gli overload rispetto agli overload. Esamina la discussione di typing collegata e gli esempi, quindi determina il comportamento del strictness flag e verifica che il controllo sia disabilitato per impostazione predefinita, pur rimanendo disponibile tramite il flag.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- compilers
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100