Disable comparison overlap checks in assert statements
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
Feature
In assert statements, allow comparisons that don't appear to overlap. These are common in test cases, and tend to generate false positives.
One way to implement this would be to filter out errors with the comparison-overlap error code in assert statements.
A potentially better way would be to not narrow down types in comparisons in assert statements, but this could be too complicated and ad hoc.
Example where we have a false positive:
# mypy: strict-equality
from enum import Enum
class MyEnum(Enum):
X = 1
Y = 2
class MyClass:
attr: MyEnum = MyEnum.X
def mutate(self) -> None:
self.attr = MyEnum.Y
def test_foo() -> None:
a = MyClass()
assert a.attr == MyEnum.X
a.mutate()
assert a.attr == MyEnum.Y # Error: Non-overlapping equality check
Pitch
These errors are often false positives, and they are somewhat frequent in test cases. The fix seems simple.
Hints
Here is an example of filtering errors adapted from mypy/plugins/default.py:
with self.msg.filter_errors(
filter_errors=lambda name, info: info.code != codes.TYPEDDICT_READONLY_MUTATED,
save_filtered_errors=True,
):
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、assert 文がどのようにチェックされ、comparison-overlap error がどのように生成されるかを追跡してください。参照として mypy/plugins/default.py の filtering の例を使用してください。assert 文内の重複しない比較でこのエラーが出力されなくなり、通常の比較では既存の動作が維持されれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- tooling
- issue の種類
- 機能追加
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 38/100