python / python/mypy

Feature Request: a secondary error for overrides based on compatibility

Aperta
#17,243 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

feature
Lingua principale
Python
Stelle
20.6k
Fork
3.3k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

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.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia con i controlli di compatibilità degli override che emettono l’errore [override], usando la sezione incompatible-overrides della documentazione di mypy e gli esempi di questa issue. Definisci come distinguere il restringimento degli argomenti da una firma di chiamata sostanzialmente diversa, quindi aggiungi una copertura che mostri che ogni caso riceve la diagnostica prevista.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
devtools
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

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.