Title: Callable iterator can SystemError if call exhausts the iterator · Issue #101892 · python/cpython · GitHub
Open Graph Title: Callable iterator can SystemError if call exhausts the iterator · Issue #101892 · python/cpython
X Title: Callable iterator can SystemError if call exhausts the iterator · Issue #101892 · python/cpython
Description: Bug report If the callable of a callable iterator (with sentinel) exhausts the iterator itself during the call, a SystemError occurs. Example discovered by @chilaxan def bug(): if bug.clear: return 1 else: bug.clear = True list(bug.itera...
Open Graph Description: Bug report If the callable of a callable iterator (with sentinel) exhausts the iterator itself during the call, a SystemError occurs. Example discovered by @chilaxan def bug(): if bug.clear: return...
X Description: Bug report If the callable of a callable iterator (with sentinel) exhausts the iterator itself during the call, a SystemError occurs. Example discovered by @chilaxan def bug(): if bug.clear: return...
Opengraph URL: https://github.com/python/cpython/issues/101892
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Callable iterator can SystemError if call exhausts the iterator","articleBody":"# Bug report\r\n\r\nIf the callable of a callable iterator (with sentinel) exhausts the iterator itself during the call, a SystemError occurs.\r\n\r\n\u003e Example discovered by @chilaxan \r\n```python\r\ndef bug():\r\n if bug.clear:\r\n return 1\r\n else:\r\n bug.clear = True\r\n list(bug.iterator)\r\n return 0\r\n\r\nbug.iterator = iter(bug, 1)\r\nbug.clear = False\r\nnext(bug.iterator)\r\n```\r\n```\r\nSystemError: Objects\\object.c:722: bad argument to internal function\r\n```\r\n\r\n# Likely cause\r\n`iterobject.calliter_iternext` does not check whether `it-\u003eit_sentinel` is NULL after the `_PyObject_CallNoArgs` call\r\nhttps://github.com/python/cpython/blob/main/Objects/iterobject.c#L207-L237\r\n\r\n```diff\r\nstatic PyObject *\r\ncalliter_iternext(calliterobject *it)\r\n{\r\n PyObject *result;\r\n\r\n if (it-\u003eit_callable == NULL) {\r\n return NULL;\r\n }\r\n\r\n+ result = _PyObject_CallNoArgs(it-\u003eit_callable);\r\n if (result != NULL) {\r\n int ok;\r\n\r\n+ ok = PyObject_RichCompareBool(it-\u003eit_sentinel, result, Py_EQ);\r\n if (ok == 0) {\r\n return result; /* Common case, fast path */\r\n }\r\n(...)\r\n```\r\n\r\n# Your environment\r\nAppears to affect 3.7-3.12\r\n\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-101896\n* gh-102418\n* gh-102422\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/ionite34","@type":"Person","name":"ionite34"},"datePublished":"2023-02-13T23:27:37.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/101892/cpython/issues/101892"}
| 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:eadf6990-2e1f-b33b-49a0-8b18748c758c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B1CA:25F5D0:8F21F0:C19563:6969BE86 |
| html-safe-nonce | 25f82d0ad7d78c6e9d30cc629c41d8f16f34f7cf6c9dd6ad0079f0fbf2cda97d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMUNBOjI1RjVEMDo4RjIxRjA6QzE5NTYzOjY5NjlCRTg2IiwidmlzaXRvcl9pZCI6IjIxMTY4MzgyMjA1OTI5NTUwMTQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | e3c93e952b176bcb395b1848a4dab5d26dd6a5c8318b6b587ce6debeb842e2f9 |
| hovercard-subject-tag | issue:1583230785 |
| 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/101892/issue_layout |
| twitter:image | https://opengraph.githubassets.com/7be6f0a09eb449469c285c4e00510c010f64c9a7c818cbef0b8e14bd4c7002b7/python/cpython/issues/101892 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/7be6f0a09eb449469c285c4e00510c010f64c9a7c818cbef0b8e14bd4c7002b7/python/cpython/issues/101892 |
| og:image:alt | Bug report If the callable of a callable iterator (with sentinel) exhausts the iterator itself during the call, a SystemError occurs. Example discovered by @chilaxan def bug(): if bug.clear: return... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ionite34 |
| hostname | github.com |
| expected-hostname | github.com |
| None | acedec8b5f975d9e3d494ddd8f949b0b8a0de59d393901e26f73df9dcba80056 |
| 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 | 83c08c21cdda978090dc44364b71aa5bc6dcea79 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width