Skip to content

"Yield value expected" on generator using send() #10997

@bgreen-litl

Description

@bgreen-litl

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-runtime-semanticsmypy doesn't model runtime semantics correctly

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions