New submission from Antal Nemes <thoneyva...@gmail.com>:
Reproducible with current master (3.9, 151b91dfd21a100ecb1eba9e293c0a8695bf3bf5) I would expect itertools.combinations to be lazy in the sense that it should not exhaust the input iterator in constructor time. import itertools; itertools.combinations(itertools.count(),2) should return instantly. Instead it "hangs" until the process is killed. Similarly, one can reproduce with the following simple crafted generator: Python 3.9.0a0 (heads/master-dirty:151b91d, Jul 24 2019, 19:51:53) [GCC 5.4.0 20160609] on linux Type "help", "copyright", "credits" or "license" for more information. >>> def mygenerator_with_exception(): yield 2 yield 2 yield 3 raise Exception("Should not be raised") ... ... ... ... ... >>> g = mygenerator_with_exception() >>> import itertools >>> itertools.combinations(g,2) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<stdin>", line 5, in mygenerator_with_exception Exception: Should not be raised Could you please consider making itertools.combinations truely lazy? ---------- components: Interpreter Core messages: 348395 nosy: furiel priority: normal severity: normal status: open title: itertools.combinations could be lazier type: behavior versions: Python 3.5, Python 3.9 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue37671> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com