Skip to content

"yield from f()" infers wrong type for type variable #3808

@lincolnq

Description

@lincolnq

I have the following test case on mypy 0.521:

from typing import Generator, TypeVar
T = TypeVar('T')
def f(v: T) -> Generator[None, None, T]:
    yield
    return v

def g() -> Generator[None, None, None]:
    # This works:
    gen = f(1)
    result_int = yield from gen

    # This breaks:
    result_int_2 = yield from f(1)
    # I get
    #  mypy_bug.py:13: error: Function does not return a value
    #  mypy_bug.py:13: error: Argument 1 to "f" has incompatible type "int"; expected None

I expected this to type-check, but instead it complains on the last line. (I'm using strict-optional, although I don't think that is essential to this example)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions