python / python/mypy

Feature Request: a secondary error for overrides based on compatibility

Abierto
#17,243 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

feature
Lenguaje dominante
Python
Estrellas
20.6k
Forks
3.3k
Métricas de merge de PR
Métricas de PR pendientes

Descripción

Feature

Apologies if I this has been discussed before. I did search the archives for past issues.

I am porting a legacy project to mypy and have run into several issues with LSP that generate a [override] error as outlined on https://mypy.readthedocs.io/en/stable/common_issues.html#incompatible-overrides

As I've been working on this effort, I've noticed two main situations that generate this issue. I'll use the examples on the docs to illustrate

Given:

from typing import Sequence, List, Iterable

class A:
    def test(self, t: Sequence[int]) -> Sequence[str]:
        ...

1- Most problems are due to a narrowing of the argument, as the docs show

class NarrowerArgument(A):
    def test(self, t: List[int]) -> Sequence[str]:  # type: ignore[override]
        ...

2- However, some problems are due to a developer completely breaking the API, such as changing the input variables and types completely:

class WildlyDifferent(A):
    def test(self, tt: List[str], foo:int) -> Sequence[str]:  # type: ignore[override]
        ...

Both of these situations generate the same error codes, meaning an ignore for one will ignore the other.

Pitch

I think it would be incredibly useful to people porting legacy code if overrides could be broken down into (at-least) these two types, so they can be triaged and scheduled into sprints accordingly.

When dealing with large legacy projects, these errors are plentiful. While the narrowing of input values for Type Safety needs to be addressed, that need is often secondary to addressing the invocation of a function that uses a wildly different call signature - and has likely missed unit tests and code coverage for several years of API/Library updates.

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 con las comprobaciones de compatibilidad de sobrescrituras que emiten el error [override], usando la sección incompatible-overrides de la documentación de mypy y los ejemplos de este issue. Define cómo deben distinguirse los argumentos que se estrechan de una firma de llamada sustancialmente diferente y añade cobertura que muestre que cada caso recibe el diagnóstico previsto.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
python
Área
devtools
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.