Code after `yield from` a generator that cannot end should be unreachable
オープン
まだ誰も着手していません。
bug
topic-reachability
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
Bug Report
Split off from https://github.com/python/mypy/issues/7374#issuecomment-944883194
To Reproduce
from typing import Generator, NoReturn, Union
def inf() -> Generator[str, None, NoReturn]:
while True:
yield "xyz"
def generate(x: Union[str, int]) -> Generator[str, None, int]:
if isinstance(x, str):
yield from inf() # `yield from` will never return, because the generator never returns
return x # error: Incompatible return value type (got "Union[str, int]", expected "int")
Expected Behavior
No error
Actual Behavior
An error.
Your Environment
Reproduced in mypy-play.
- Mypy version used: 1.16.1
- Mypy command-line flags: N/A
- Mypy configuration options from
mypy.ini(and other config files): N/A - Python version used: 3.12
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
報告された mypy 1.16.1 環境で mypy-play の例を再現し、NoReturn ジェネレーターの yield from 後における制御フローの処理に焦点を当てます。関連するジェネレーターおよび戻り値型の解析エントリーポイントを追跡します。完了条件は、他の戻り値チェックを維持したまま、例が互換性のない戻り値に関するエラーを生成しないことです。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100