Feature Request: a secondary error for overrides based on compatibility
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
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.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit den Kompatibilitätsprüfungen für Überschreibungen, die den Fehler [override] ausgeben, unter Verwendung des Abschnitts incompatible-overrides in der mypy-Dokumentation und der Beispiele in diesem Issue. Lege fest, wie das Verengen von Argumenten von einer wesentlich anderen Aufrufsignatur unterschieden werden soll, und füge Tests hinzu, die zeigen, dass jeder Fall die dafür vorgesehene Diagnose erhält.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- devtools
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100