Bad error message while checking subclass of generic classes
オープン
まだ誰も着手していません。
bug
topic-error-reporting
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
Bug Report
mypy command on a misspecified subclass of a generic class returns a pretty confusing error message (As per issue #8696)
To Reproduce
- Create a script containing this snippet:
from abc import ABC, abstractmethod
from typing import TypeVar, Iterable, Iterator
T = TypeVar('T')
class MyABC(ABC):
@property
@abstractmethod
def items(self) -> Iterable[T]: ...
def my_method(self) -> Iterator[T]:
for item in self.items:
yield item
- Run mypy on the created script
Expected Behavior
Since MyABC should inherit also from Generic[T] I'd expect that the error message would return something on the line of:
error: Incompatible types in "yield". The class should inherit from "Generic[T]"
Actual Behavior
The actual error message is:
error: Incompatible types in "yield" (actual type "T", expected type "T")
Environment
- Mypy version used: 0.910
- Mypy command-line flags: None
- Mypy configuration options from
mypy.ini(and other config files): default - Python version used: 3.6.5
- Operating system and version: MacOS BigSur 11.5.2
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず issue 内の最小スクリプトに対して mypy を実行し、紛らわしい yield の診断を確認します。リポジトリのファイル名やテスト名は示されていないため、mypy コマンドのエントリポイントから診断を追跡し、その後、誤って指定されたジェネリックサブクラスが、欠落している Generic[T] の継承を特定する実用的なメッセージを生成することを確認します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- tooling
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100