Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: a secondary error for overrides based on compatibility #17243

Open
jvanasco opened this issue May 14, 2024 · 0 comments
Open
Labels

Comments

@jvanasco
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant