Title: Async generator/anext with default-tuple-value results in SystemError:
Open Graph Title: Async generator/anext with default-tuple-value results in SystemError:
X Title: Async generator/anext with default-tuple-value results in SystemError:
Description: Bug report Bug description: I asked a question on stackoverflow because I found a strange error while writing code that makes use an async generator function and the built-in anext() function when using a tuple value for the default argu...
Open Graph Description: Bug report Bug description: I asked a question on stackoverflow because I found a strange error while writing code that makes use an async generator function and the built-in anext() function when ...
X Description: Bug report Bug description: I asked a question on stackoverflow because I found a strange error while writing code that makes use an async generator function and the built-in anext() function when ...
Opengraph URL: https://github.com/python/cpython/issues/128078
X: @github
Domain: github.com
IPv4 address: 140.82.114.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Async generator/anext with default-tuple-value results in SystemError: \u003cclass 'StopIteration'> returned with exception set","articleBody":"# Bug report\r\n\r\n### Bug description:\r\n\r\nI asked a question on [stackoverflow](https://stackoverflow.com/questions/79289349/why-does-this-async-generator-anext-snippet-result-in-systemerror-class-stopi) because I found a strange error while writing code that makes use an async generator function and the built-in `anext()` function when using a tuple value for the `default` argument of `anext()`.\r\n\r\nOne of the [stackoverflow answers](https://stackoverflow.com/a/79289763/3379953) contains a good analysis and a possible cause of the problem.\r\n\r\nThe failing code is the second line with `anext()`:\r\n\r\n```python\r\nimport asyncio\r\n\r\nasync def generator(it=None):\r\n if it is not None:\r\n yield (it, it)\r\n\r\nasync def my_func():\r\n # results in a=1 b=1\r\n a, b = await anext(generator(1), (2, 3))\r\n \r\n # results in no printing\r\n async for a, b in generator():\r\n print(a, b)\r\n \r\n # raises exception\r\n a, b = await anext(generator(), (2, 3))\r\n\r\nloop = asyncio.new_event_loop()\r\nloop.run_until_complete(my_func())\r\n```\r\n\r\nIt raises this unexpected exception:\r\n\r\n```shell\r\nStopAsyncIteration\r\n\r\nThe above exception was the direct cause of the following exception:\r\n\r\nTraceback (most recent call last):\r\n File \"\u003cstdin>\", line 1, in \u003cmodule>\r\n File \"/Users/manuel/.pyenv/versions/3.12.0/lib/python3.12/asyncio/base_events.py\", line 664, in run_until_complete\r\n return future.result()\r\n ^^^^^^^^^^^^^^^\r\n File \"\u003cstdin>\", line 6, in my_func\r\nSystemError: \u003cclass 'StopIteration'> returned a result with an exception set\r\n```\r\n\r\n\r\n### CPython versions tested on:\r\n\r\n3.11, 3.12, 3.13\r\n\r\n### Operating systems tested on:\r\n\r\nmacOS\r\n\r\n\u003c!-- gh-linked-prs -->\r\n### Linked PRs\r\n* gh-128780\r\n* gh-128784\r\n* gh-128785\r\n* gh-128287\r\n* gh-128789\r\n* gh-128790\r\n\u003c!-- /gh-linked-prs -->\r\n","author":{"url":"https://github.com/manuel-koch","@type":"Person","name":"manuel-koch"},"datePublished":"2024-12-18T18:57:33Z","url":"https://github.com/python/cpython/issues/128078"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:a2813d00-6141-5ecc-3396-ad43901ae795 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D0C6:83634:E69814:1346746:6B064C02 |
| html-safe-nonce | ccbcc1b87269c3bdb6f480fa108a7ebc7629767bb725be9bb5950716a6e3c7dc |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMEM2OjgzNjM0OkU2OTgxNDoxMzQ2NzQ2OjZCMDY0QzAyIiwidmlzaXRvcl9pZCI6IjYzNTc5NzY2NTI4NDQ1MTg0MDIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | df8632beecd3f1ed65f2eeb6528b73699683d2d350d9f7afeb12dfa2948ba895 |
| hovercard-subject-tag | issue:2748536442 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/128078/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b6a6dc486d3f87f30dd8a320c4a7445a948805a898ba8ba0251aeff99127042b/python/cpython/issues/128078 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b6a6dc486d3f87f30dd8a320c4a7445a948805a898ba8ba0251aeff99127042b/python/cpython/issues/128078 |
| og:image:alt | Bug report Bug description: I asked a question on stackoverflow because I found a strange error while writing code that makes use an async generator function and the built-in anext() function when ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | manuel-koch |
| hostname | github.com |
| expected-hostname | github.com |
| None | 772b6997ca4daa0428dd49a25d76052e765555ae560fe9c88517eb828bbd861e |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | f1f9a08f7c769a37f1dfc18ad43d463c222a7eea |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width