Feature Request: a secondary error for overrides based on compatibility
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
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.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
[override] エラーを出力するオーバーライド互換性チェックから始め、mypy ドキュメントの incompatible-overrides セクションと、この issue の例を使用します。引数の絞り込みと、実質的に異なる呼び出しシグネチャをどのように区別するかを定義し、それぞれのケースが意図した診断を受けることを示すカバレッジを追加します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- devtools
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100