Title: Incomplete stack traces when throwing into a generator chain that ends in a custom generator · Issue #126091 · python/cpython · GitHub
Open Graph Title: Incomplete stack traces when throwing into a generator chain that ends in a custom generator · Issue #126091 · python/cpython
X Title: Incomplete stack traces when throwing into a generator chain that ends in a custom generator · Issue #126091 · python/cpython
Description: Bug report Bug description: bpo-29590 identified an issue where only the head of a chain of generators was included in stack-traces when processing a thrown-in exception. I think this issue still exists but only in the case where the hea...
Open Graph Description: Bug report Bug description: bpo-29590 identified an issue where only the head of a chain of generators was included in stack-traces when processing a thrown-in exception. I think this issue still e...
X Description: Bug report Bug description: bpo-29590 identified an issue where only the head of a chain of generators was included in stack-traces when processing a thrown-in exception. I think this issue still e...
Opengraph URL: https://github.com/python/cpython/issues/126091
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Incomplete stack traces when throwing into a generator chain that ends in a custom generator","articleBody":"# Bug report\r\n\r\n### Bug description:\r\n\r\n[bpo-29590](https://bugs.python.org/issue29590) identified an issue where only the head of a chain of generators was included in stack-traces when processing a thrown-in exception. I think this issue still exists but only in the case where the head of a chain of generators is a custom generator.\r\n\r\nConsider the following example in which a custom generator's `throw()` method does not see its predecessor in the `yield from` chain (the `g()` generator), but the builtin in generator does:\r\n```python\r\n$ cat test.py\r\nimport sys\r\n\r\nclass UserGen:\r\n def throw(self, *args):\r\n print(\"Traceback from UserGen:\")\r\n f = sys._getframe()\r\n while f:\r\n print(f)\r\n f = f.f_back\r\n def __iter__(self):\r\n return self\r\n def __next__(self):\r\n return 42\r\n\r\ndef real_gen():\r\n yield 43\r\n\r\ndef g(target):\r\n yield from target\r\n\r\ngg = g(UserGen())\r\ngg.send(None)\r\ngg.throw(RuntimeError)\r\n\r\nprint()\r\n\r\ngg = g(real_gen())\r\ngg.send(None)\r\ngg.throw(RuntimeError)\r\n\r\n\r\n$ python3 test.py\r\nTraceback from UserGen:\r\n\u003cframe at 0x10273e230, file 'test.py', line 8, code throw\u003e\r\n\u003cframe at 0x10270d440, file 'test.py', line 26, code \u003cmodule\u003e\u003e\r\n\r\nTraceback (most recent call last):\r\n File \"test.py\", line 32, in \u003cmodule\u003e\r\n gg.throw(RuntimeError)\r\n File \"test.py\", line 22, in g\r\n yield from target\r\n File \"test.py\", line 18, in real_gen\r\n yield 43\r\nRuntimeError\r\n```\r\n\r\nThe fix for [bpo-29590](https://bugs.python.org/issue29590) is in #19896 and appears to specifically only link frames together for chains of builtin generators only. I *suspect* this was just an oversight rather than a deliberate choice though.\r\n\r\nI attach a proposed fix in a PR.\r\n\r\n### CPython versions tested on:\r\n\r\nCPython main branch\r\n\r\n### Operating systems tested on:\r\n\r\n_No response_\r\n\r\n\u003c!-- gh-linked-prs --\u003e\r\n### Linked PRs\r\n* gh-126092\r\n\u003c!-- /gh-linked-prs --\u003e\r\n","author":{"url":"https://github.com/jbower-fb","@type":"Person","name":"jbower-fb"},"datePublished":"2024-10-28T20:32:23.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/126091/cpython/issues/126091"}
| 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:970530a8-f044-0135-31ea-4596a1223bab |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 840A:F5661:21E2C2A:2E29008:696ACA08 |
| html-safe-nonce | f9b7a1834be632a84c3d44b3e3fb68e11bce4f43dbf118bd55d80c35b44e1aed |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NDBBOkY1NjYxOjIxRTJDMkE6MkUyOTAwODo2OTZBQ0EwOCIsInZpc2l0b3JfaWQiOiI1ODUwNTU4NjQwOTk2MjEzODQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | e2c6c9e722c0287c7ce3290db366bcfcb48145a10f9dbaaf65bb5368d24cb79b |
| hovercard-subject-tag | issue:2619478072 |
| 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/126091/issue_layout |
| twitter:image | https://opengraph.githubassets.com/34418338a48a886e17555e49f84e8c2ea4445373e334bc6863769f6974fd7a9c/python/cpython/issues/126091 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/34418338a48a886e17555e49f84e8c2ea4445373e334bc6863769f6974fd7a9c/python/cpython/issues/126091 |
| og:image:alt | Bug report Bug description: bpo-29590 identified an issue where only the head of a chain of generators was included in stack-traces when processing a thrown-in exception. I think this issue still e... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jbower-fb |
| hostname | github.com |
| expected-hostname | github.com |
| None | c785f4ce187e9e7331257791b36ddee01625bb8e292a9b4fe2c16d4c006abf5d |
| 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 | c718a376fcf780eb22089171adb84a543f660bf7 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width