{"action":"created","issue":{"url":"https://api.github.com/repos/numba/numba/issues/2165","repository_url":"https://api.github.com/repos/numba/numba","labels_url":"https://api.github.com/repos/numba/numba/issues/2165/labels{/name}","comments_url":"https://api.github.com/repos/numba/numba/issues/2165/comments","events_url":"https://api.github.com/repos/numba/numba/issues/2165/events","html_url":"https://github.com/numba/numba/issues/2165","id":184284665,"number":2165,"title":"Iterators do not get properly consumed inside generators","user":{"login":"ma-ba","id":10598343,"avatar_url":"https://avatars.githubusercontent.com/u/10598343?v=3","gravatar_id":"","url":"https://api.github.com/users/ma-ba","html_url":"https://github.com/ma-ba","followers_url":"https://api.github.com/users/ma-ba/followers","following_url":"https://api.github.com/users/ma-ba/following{/other_user}","gists_url":"https://api.github.com/users/ma-ba/gists{/gist_id}","starred_url":"https://api.github.com/users/ma-ba/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ma-ba/subscriptions","organizations_url":"https://api.github.com/users/ma-ba/orgs","repos_url":"https://api.github.com/users/ma-ba/repos","events_url":"https://api.github.com/users/ma-ba/events{/privacy}","received_events_url":"https://api.github.com/users/ma-ba/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-10-20T16:56:56Z","updated_at":"2016-10-21T13:52:56Z","closed_at":null,"body":"Using `Numba 0.29.0`.\r\nIn the following code\r\n - `yield_from_iter` shows the aberrant behavior,\r\n - `yield_from_iter_loop` only illustrates the same behavior inside a loop,\r\n - `list_from_iter_loop` shows the correct behavior while returning a list instead of being a generator.\r\n```python\r\nfrom numba import njit\r\n\r\n\r\ndef yield_from_iter(a, sep):\r\n    i = iter(a)\r\n    for x in i:\r\n        yield x\r\n    # `i` _should_ be consumed by now, but only its first element is\r\n    yield sep\r\n    for x in i:\r\n        yield x\r\n    yield sep\r\n\r\n\r\ndef yield_from_iter_loop(a, sep):\r\n    i = iter(a)\r\n    for _ in range(len(a)+2):\r\n        for x in i:\r\n            yield x\r\n        # `i` _should_ be consumed by now,\r\n        # but only one element per iteration gets consumed\r\n        yield sep\r\n\r\n\r\ndef list_from_iter_loop(a, sep):\r\n    i = iter(a)\r\n    ret = []\r\n    for _ in range(len(a)+2):\r\n        for x in i:\r\n            ret.append(x)\r\n        # when saving into a list, `i` is completely consumed now\r\n        ret.append(sep)\r\n    return ret\r\n\r\n\r\na = list(range(4))\r\nsep = 999\r\nfor pyfunc in (yield_from_iter,\r\n               yield_from_iter_loop,\r\n               list_from_iter_loop):\r\n    cfunc = njit()(pyfunc)\r\n    print(pyfunc.__name__)\r\n    print(\" pyfunc:\", list(pyfunc(a, sep)))\r\n    print(\" cfunc :\", list(cfunc(a, sep)))\r\n```\r\noutput:\r\n```python\r\nyield_from_iter\r\n pyfunc: [0, 1, 2, 3, 999, 999]\r\n cfunc : [0, 1, 2, 3, 999, 1, 2, 3, 999]\r\nyield_from_iter_loop\r\n pyfunc: [0, 1, 2, 3, 999, 999, 999, 999, 999, 999]\r\n cfunc : [0, 1, 2, 3, 999, 1, 2, 3, 999, 2, 3, 999, 3, 999, 999, 999]\r\nlist_from_iter_loop\r\n pyfunc: [0, 1, 2, 3, 999, 999, 999, 999, 999, 999]\r\n cfunc : [0, 1, 2, 3, 999, 999, 999, 999, 999, 999]\r\n```\r\n```"},"comment":{"url":"https://api.github.com/repos/numba/numba/issues/comments/255382798","html_url":"https://github.com/numba/numba/issues/2165#issuecomment-255382798","issue_url":"https://api.github.com/repos/numba/numba/issues/2165","id":255382798,"user":{"login":"ma-ba","id":10598343,"avatar_url":"https://avatars.githubusercontent.com/u/10598343?v=3","gravatar_id":"","url":"https://api.github.com/users/ma-ba","html_url":"https://github.com/ma-ba","followers_url":"https://api.github.com/users/ma-ba/followers","following_url":"https://api.github.com/users/ma-ba/following{/other_user}","gists_url":"https://api.github.com/users/ma-ba/gists{/gist_id}","starred_url":"https://api.github.com/users/ma-ba/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ma-ba/subscriptions","organizations_url":"https://api.github.com/users/ma-ba/orgs","repos_url":"https://api.github.com/users/ma-ba/repos","events_url":"https://api.github.com/users/ma-ba/events{/privacy}","received_events_url":"https://api.github.com/users/ma-ba/received_events","type":"User","site_admin":false},"created_at":"2016-10-21T13:52:56Z","updated_at":"2016-10-21T13:52:56Z","body":"Correct, this is not a new regression but was also observed in 0.28.1 just before updating to 0.29."}}
{"actor":{"display_login":"ma-ba"}}