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 https://github.com/python/cpython/issues/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
Description
The following code terminates before the refactoring but not after:
This is because
itertools.product
tries to exhaust the iterators before outputting anything, so does not work with infinite iterators, as in https://github.com/python/cpython/issues/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