python / python/mypy

Relax default overload subtyping checks

Abierto
#20,720 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

false-positive feature topic-overloads
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:

https://github.com/python/mypy/blob/9f157d988f4da3624b0c58a2e7dd5f777bc8a755/mypy/subtypes.py#L1003-L1009

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:

  1. Argument signatures are mutually exclusive mypy-playground

  2. Argument types are mutually exclusive (e.g. via @disjoint_bases) mypy-playground

  3. 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

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. 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

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.