Skip to content

Yield not working with iterator annotation #657

Open
@migeed-z

Description

@migeed-z

Describe the Bug

from typing import Iterable, TypeVar, Iterator
_T = TypeVar("_T")

def f(start, iterable: Iterable[_T], step) ->  Iterator[_T]:
    next_i = start
    for i, element in enumerate(iterable):
        if i == next_i:
            yield element # E: Type of yielded value `_T` is not assignable to declared return type `_T`
            next_i += step

should not emit at error on yield element.

Sandbox Link

https://pyrefly.org/sandbox/?code=GYJw9gtgBALgngBwJYDsDmUkQWEMoCSMApiAIYBGANsQDRQAqixAamSPUaWTLgFAB9BlAC8jZmxAAKAERCZASj58AJsWBRgUgM4x2MekhLlqxAFyFjlGgG0hAXXq7iCBVAC0APiiXuvEHYM9mZ8Pj4oxAAeMAJIolC6+qFhwLiY9MQ0EMQo+KhQOQCu2eQkUkbcpgohYbWYGnEiYhHRsTV1HXBImSoFWTkwyR21LTFxANRizgh8QA

(Only applicable for extension issues) IDE Information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions