Relax default overload subtyping checks
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 20.6k
- Forks
- 3.3k
- Métricas de merge de PR
- Métricas de PR pendientes
Descripción
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.
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza en mypy/subtypes.py, en las líneas 1003-1009, e inspecciona cómo se comprueban los overloads frente a otros overloads. Revisa la discusión de typing enlazada y los ejemplos; después, determina el comportamiento del strictness flag y verifica que la comprobación esté deshabilitada de forma predeterminada, aunque siga disponible mediante el flag.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- compilers
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100