Skip to content
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

use-itertools-product changes functionality involving infinite generators #281

Closed
ronnodas opened this issue Sep 15, 2022 · 2 comments
Closed
Assignees
Labels
bug Something isn't working next release This will be fixed in next release

Comments

@ronnodas
Copy link

Description

The following code terminates before the refactoring but not after:

from itertools import count, product

def loop():
    for x in count():
        for y in range(5):
            if x == 3:
                return y

print(loop())

This is because itertools.product tries to exhaust the iterators before outputting anything, so does not work with infinite iterators, as in python/cpython#54318.

I'm really not sure what the right thing to do is, since it's a useful refactoring in most cases. Maybe the safe solution is to only trigger if each of the iterables is known to be a finite iterator (eg list, tuple, range, ...)?

Debug Information

IDE Version:
PyCharm Professional Edition 2022.2.1

Sourcery Version:
Sourcery 0.12.8

Operating system and Version:
Fedora Linux 36

@ronnodas ronnodas added the bug Something isn't working label Sep 15, 2022
@Hellebore
Copy link
Collaborator

Thanks for raising! Yeah this is a tricky one to restrict without cutting out a bunch of the useful cases. Will have a think.

@Hellebore Hellebore self-assigned this Sep 20, 2022
@Hellebore Hellebore added the next release This will be fixed in next release label Sep 23, 2022
@Hellebore
Copy link
Collaborator

Fixed with 0.12.9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working next release This will be fixed in next release
Projects
None yet
Development

No branches or pull requests

2 participants