When you're using generator and any() the rest of the code after first yielding True will be omitted.
I understand the logic behind it but it looks a bit like an issue or rake and should be documented in https://docs.python.org/3/library/functions.html#any at least.
def f():
print(1, end=' ')
yield False
print(2, end=' ')
yield True
print(3, end=' ')
print(any(f()))
# 1 2 True
print(list(f()))
# 1 2 3 [False, True]
for i in f():
print(i, end=' ')
# 1 False 2 True 3
Real life example of stepping on this rake: xonsh/xonsh#5539
CPython versions tested on:
3.10, 3.12
Operating systems tested on:
Linux, macOS
When you're using generator and
any()the rest of the code after first yielding True will be omitted.I understand the logic behind it but it looks a bit like an issue or rake and should be documented in https://docs.python.org/3/library/functions.html#any at least.
Real life example of stepping on this rake: xonsh/xonsh#5539
CPython versions tested on:
3.10, 3.12
Operating systems tested on:
Linux, macOS