python / python/mypy

"Yield value expected" on generator using send()

オープン
#10,997 コメント 3 件 リアクション 10 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

bug topic-runtime-semantics
主要言語
Python
スター
20.6k
フォーク
3.3k
平均マージ
1日 18時間
マージ済み PR(30日)
54

説明

Bug Report

mypy doesn't allow empty yield statements in generator functions that accept send() values

To Reproduce


from typing import Any, Generator


def foo() -> Generator[int, Any, None]:
    yield
    while True:
        yield 42

Expected Behavior

I expected the second parameter (Any) in Generator[int, Any, None] to indicate that this generator accepts a send() value and that therefore the naked yield statement is accepting a value but not sending one. As far as I know the above code is idiomatic.

Actual Behavior

error: Yield value expected

mypy complains that a yield value is expected, but this standalone yield is for the purpose of accepting the value of a send() to the generator.

Your Environment

mypy 0.812
python 3.7

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、提供された Python の例を mypy で実行し、「Yield value expected」診断を確認します。mypy がジェネレーターの yield 文と Generator の send 型をどのようにチェックするかを追跡します。この場合に単独の yield が受け入れられ、例に対するリグレッションカバレッジが追加されれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
devtools
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。