Skip to content

Fails with generator + islice #165

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
shkarupa-alex opened this issue Mar 21, 2025 · 0 comments
Open

Fails with generator + islice #165

shkarupa-alex opened this issue Mar 21, 2025 · 0 comments

Comments

@shkarupa-alex
Copy link

shkarupa-alex commented Mar 21, 2025

Here is an example

from fast_depends import inject, Depends
from itertools import islice

def simple_dependency(a: int, b: int = 3):
    return a + b

@inject
def method(a: int, d: int = Depends(simple_dependency)) -> Generator[int, None, None]:
    yield from range(a + d)

# iterator = iter(list(method(5))) # this works
iterator = iter(method(5)) # but this is not

while batch := tuple(islice(iterator, 2)): # itertools.batched
    print(batch) # prints (1, 2) forever
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant