Title: contextlib.suppress does not support ExceptionGroups · Issue #103791 · python/cpython · GitHub
Open Graph Title: contextlib.suppress does not support ExceptionGroups · Issue #103791 · python/cpython
X Title: contextlib.suppress does not support ExceptionGroups · Issue #103791 · python/cpython
Description: Currently, contextlib.suppress does not successfully suppress exceptions that are wrapped within an ExceptionGroup. In other words, this works: def raise_ve(): raise ValueError("ve") with suppress(ValueError): raise_ve() while this doesn...
Open Graph Description: Currently, contextlib.suppress does not successfully suppress exceptions that are wrapped within an ExceptionGroup. In other words, this works: def raise_ve(): raise ValueError("ve") with suppress(...
X Description: Currently, contextlib.suppress does not successfully suppress exceptions that are wrapped within an ExceptionGroup. In other words, this works: def raise_ve(): raise ValueError("ve") with...
Opengraph URL: https://github.com/python/cpython/issues/103791
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"contextlib.suppress does not support ExceptionGroups","articleBody":"Currently, `contextlib.suppress` does not successfully suppress exceptions that are wrapped within an `ExceptionGroup`.\r\n\r\nIn other words, this works:\r\n```python\r\ndef raise_ve():\r\n raise ValueError(\"ve\")\r\n\r\nwith suppress(ValueError):\r\n raise_ve()\r\n```\r\n\r\nwhile this doesn't:\r\n```python\r\ndef raise_ve_eg():\r\n raise ExceptionGroup(\"eg\", [ValueError(\"ve\")])\r\n\r\nwith suppress(ValueError):\r\n raise_ve_eg()\r\n```\r\n\r\nThe user's intent is to suppress the latter case, too. It should work just as well, removing `ValueError` instances from the exception group. If it ends up empty, nothing gets raised. Otherwise, an `ExceptionGroup` should be re-raised with the remaining exceptions. For instance:\r\n\r\n```python\r\ndef raise_ve_eg3():\r\n raise ExceptionGroup(\"eg\", [ValueError(\"ve1\"), KeyError(\"ke\"), ValueError(\"ve2\")])\r\n\r\nwith suppress(ValueError):\r\n raise_ve_eg3()\r\n```\r\n\r\nshould raise an `ExceptionGroup` with the `KeyError(\"ke\")` only, as we suppressed ValueError instances.\r\n\r\n\u003c!-- gh-linked-prs --\u003e\r\n### Linked PRs\r\n* gh-103792\r\n* gh-111910\n* gh-111955\n\u003c!-- /gh-linked-prs --\u003e\r\n","author":{"url":"https://github.com/ambv","@type":"Person","name":"ambv"},"datePublished":"2023-04-24T20:23:10.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/103791/cpython/issues/103791"}
| 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:cffa16f3-91dd-29f2-aea4-fefa23e20490 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | EB12:1478A3:423FAA:5DF1FD:696A0B1D |
| html-safe-nonce | 9b87849ac06ec5c3fabcfa2200bda0df039a3538a5f27119a84ef588ca240914 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQjEyOjE0NzhBMzo0MjNGQUE6NURGMUZEOjY5NkEwQjFEIiwidmlzaXRvcl9pZCI6IjQ2Mzk2MTMxODYwNDQ3MjYwNDUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | f9a2c4ba20214299ea001306a55b5d413a4578a9b803b136c8dbcdd1b130f729 |
| hovercard-subject-tag | issue:1681973371 |
| 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/103791/issue_layout |
| twitter:image | https://opengraph.githubassets.com/a40cb2a01ae398dcdd2c146b16584a3b917c24e173ccb8c6efa4f76d1a1f150d/python/cpython/issues/103791 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/a40cb2a01ae398dcdd2c146b16584a3b917c24e173ccb8c6efa4f76d1a1f150d/python/cpython/issues/103791 |
| og:image:alt | Currently, contextlib.suppress does not successfully suppress exceptions that are wrapped within an ExceptionGroup. In other words, this works: def raise_ve(): raise ValueError("ve") with suppress(... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ambv |
| hostname | github.com |
| expected-hostname | github.com |
| None | 699227a00bbb7fe1eec276d2ae1c3a93068bc5ba483bd9dc4b2a27a8f4f2f595 |
| 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 | 7266b2d935baa1c6474b16dd9feaa5ca30607261 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width