KEMBAR78
No type checking error for a function that returns a value and yields · Issue #11222 · python/typeshed · GitHub
Skip to content

No type checking error for a function that returns a value and yields #11222

@Akuli

Description

@Akuli

Today I had this bug, and mypy didn't catch it:

from collections.abc import Iterator

def get_strings(foo: bool) -> Iterator[str]:
    if foo:
        return ["foo1", "foo2"]
    else:
        yield "bar1"
        yield "bar2"

print(list(get_strings(True)))  # empty list

IMO this should be a type checking error. It might be fixable in typeshed by adjusting how/when Generator becomes a subtype of Iterator. If it isn't, I suggest just closing this issue, because there's already so many mypy issues that this would surely be a duplicate.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions