René's URL Explorer Experiment


Title: Support non-sequence iterables in the `ExceptionGroup` API, or document the design decision · Issue #129867 · python/cpython · GitHub

Open Graph Title: Support non-sequence iterables in the `ExceptionGroup` API, or document the design decision · Issue #129867 · python/cpython

X Title: Support non-sequence iterables in the `ExceptionGroup` API, or document the design decision · Issue #129867 · python/cpython

Description: Feature or enhancement Proposal: Currently, the ExceptionGroup API only supports sequences of exceptions to its second parameter excs. This ticket suggests either: additively changing the API to support non-sequence iterables as inputs a...

Open Graph Description: Feature or enhancement Proposal: Currently, the ExceptionGroup API only supports sequences of exceptions to its second parameter excs. This ticket suggests either: additively changing the API to su...

X Description: Feature or enhancement Proposal: Currently, the ExceptionGroup API only supports sequences of exceptions to its second parameter excs. This ticket suggests either: additively changing the API to su...

Opengraph URL: https://github.com/python/cpython/issues/129867

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Support non-sequence iterables in the `ExceptionGroup` API, or document the design decision","articleBody":"# Feature or enhancement\n\n### Proposal:\n\nCurrently, the `ExceptionGroup` API only supports _sequences_ of exceptions to its second parameter `excs`.\nThis ticket suggests _either_:\n- additively changing the API to support non-sequence iterables as inputs as well.\n\nor\n- documenting why only sequences are supported.\n\nCurrently, this Python code would work:\n\n```python\nExceptionGroup(\"list\", [ValueError(), AttributeError()])  # OK\n\nExceptionGroup(\"tuple\", (ValueError(), AttributeError()))  # OK\n\nclass Niche:\n    def __getitem__(self, i):\n        if i == 0:\n            return ValueError()\n        if i == 1:\n            return AttributeError()\n        raise StopIteration\n\nExceptionGroup(\"niche\", Niche())  # OK\n```\n\n\u003e [!note]\n\u003e AFAIK, `ExceptionGroup` objects do not store the sequence passed to them, _unless_ it's a tuple object (excluding tuple subclasses). They export a new tuple (created from the passed-in sequence) or passed-in tuple [via `.exceptions`](https://docs.python.org/3/library/exceptions.html#BaseExceptionGroup.exceptions).\n\u003e Quick illustration:\n\u003e ```py\n\u003e assert ExceptionGroup(\"\", excs := [ValueError()]).exceptions is not excs  # OK\n\u003e assert ExceptionGroup(\"\", excs := (ValueError(),)).exceptions is excs  # OK\n\u003e assert ExceptionGroup(\"\", excs := type(\"\", (tuple,), {})([ValueError(),])).exceptions is not excs  # OK\n\u003e ```\n\nThis is a minimal example of a use case I would desire, which is not currently supported:\n\n```py\ndef cb1():\n    raise ValueError\n\ndef cb2():\n    raise AttributeError\n\nerrors = {}\ncallbacks = {\"module1\": cb1, \"module2\": cb2}\nfor mod, cb in callbacks.items():\n    try:\n        cb()\n    except Exception as exc:\n        errors[mod] = exc\n\nif errors:\n    raise ExceptionGroup(f\"got errors in {', '.join(errors)}\", errors.values())\n```\n\n\u003e [!important]\n\u003e **While this _can_ be simply worked around by converting the values' view into a sequence, the question is more fundamental: _why_?**\n\nThere are some [other variants of this on GitHub](https://github.com/search?q=%2FExceptionGroup%5C%28.*%2C+%28list%7Ctuple%29%5C%28%2F\u0026type=code), too (including my humble one).\n\nIt was an intentional decision to only support sequences, justifying the very first part of the constructor test:\nhttps://github.com/python/cpython/blob/1bccd6c34f82f8373c320792323bfd7f7a328bc7/Lib/test/test_exception_group.py#L39-L42\n\nBefore writing this issue, I did a research in some places that seemed like they could explain why only sequences made a cut. Namely, I:\n- read the [docs of built-in exceptions](https://docs.python.org/3/library/exceptions.html#exception-groups),\n- [checked the PEP](https://peps.python.org/pep-0654),\n- skimmed through [the relevant PR](https://github.com/python/cpython/pull/28569),\n- read the discussions in [python/exceptiongroups](https://github.com/python/exceptiongroups),\n- searched the issue tracker.\n\nI didn't have the time to read them very in depth, so I might have overlooked something; I only found this thread relevant:\n- https://github.com/python/exceptiongroups/pull/13#issuecomment-754375503\n\nWhich leads me to think that supporting `Iterable` was [initially planned](https://github.com/python/exceptiongroups/issues/6#issue-730576441) (the author meant `Iterable[Exception]` instead of `Iterable[ExceptionGroup]`), but then implicitly ignored for the sake of predicted use cases only being with sequences (lists/tuples).\nPlease note that the considerations about variadic constructor of `BaseExceptionGroup` are not relevant to this ticket.\n\nBefore writing this, I also reached out to @ZeroIntensity and @Eclips4 to discuss the topic.\n\n@Eclips4 confirmed that he saw no hard requirement for the exception sequence to be a sequence specifically, and applying this simple patch\n\n```diff\ndiff --git a/Objects/exceptions.c b/Objects/exceptions.c\nindex 154cde93168..f97eb33953f 100644\n--- a/Objects/exceptions.c\n+++ b/Objects/exceptions.c\n@@ -871,7 +871,8 @@ BaseExceptionGroup_new(PyTypeObject *type, PyObject *args, PyObject *kwds)\n         return NULL;\n     }\n\n-    if (!PySequence_Check(exceptions)) {\n+    PyTypeObject *t = Py_TYPE(exceptions);\n+    if (t-\u003etp_iter == NULL) {\n         PyErr_SetString(\n             PyExc_TypeError,\n             \"second argument (exceptions) must be a sequence\");\n```\n\n[only causes `test_bad_EG_construction__bad_excs_sequence` to fail](https://pastebin.com/rg3CTLHi).\n\nCC @iritkatriel @gvanrossum @1st1\n\n\n### Has this already been discussed elsewhere?\n\nThis is a minor feature, which does not need previous discussion elsewhere\n\n### Links to previous discussion of this feature:\n\n_No response_","author":{"url":"https://github.com/johnslavik","@type":"Person","name":"johnslavik"},"datePublished":"2025-02-08T19:59:47.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":5},"url":"https://github.com/129867/cpython/issues/129867"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:ba9a99d0-f064-0088-ea7f-cd8d725b4348
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idBBD8:228CBB:55EE66:792697:696A0E24
html-safe-nonce0038bc3017602937a13cbf9b8e02b3ec74f9247b2d673ba603c32d92bcdd3b72
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQkQ4OjIyOENCQjo1NUVFNjY6NzkyNjk3OjY5NkEwRTI0IiwidmlzaXRvcl9pZCI6IjY2MjU5Njk5MDMyNzk2NzI4NjgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmacc44bdf6cc3e809f0f22a27a00ff2e2c263b160806e0f48cbc532b07b14d5fd68
hovercard-subject-tagissue:2840236126
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/129867/issue_layout
twitter:imagehttps://opengraph.githubassets.com/497cdcb41720b403bc5a1acf370fbb397e8f333481d4628c7d8ae967bb4a98c7/python/cpython/issues/129867
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/497cdcb41720b403bc5a1acf370fbb397e8f333481d4628c7d8ae967bb4a98c7/python/cpython/issues/129867
og:image:altFeature or enhancement Proposal: Currently, the ExceptionGroup API only supports sequences of exceptions to its second parameter excs. This ticket suggests either: additively changing the API to su...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamejohnslavik
hostnamegithub.com
expected-hostnamegithub.com
None699227a00bbb7fe1eec276d2ae1c3a93068bc5ba483bd9dc4b2a27a8f4f2f595
turbo-cache-controlno-preview
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release7266b2d935baa1c6474b16dd9feaa5ca30607261
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/issues/129867#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F129867
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F129867
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/issues/129867
Reloadhttps://github.com/python/cpython/issues/129867
Reloadhttps://github.com/python/cpython/issues/129867
python https://github.com/python
cpythonhttps://github.com/python/cpython
Please reload this pagehttps://github.com/python/cpython/issues/129867
Notifications https://github.com/login?return_to=%2Fpython%2Fcpython
Fork 33.9k https://github.com/login?return_to=%2Fpython%2Fcpython
Star 71.1k https://github.com/login?return_to=%2Fpython%2Fcpython
Code https://github.com/python/cpython
Issues 5k+ https://github.com/python/cpython/issues
Pull requests 2.1k https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects 31 https://github.com/python/cpython/projects
Security Uh oh! There was an error while loading. Please reload this page. https://github.com/python/cpython/security
Please reload this pagehttps://github.com/python/cpython/issues/129867
Insights https://github.com/python/cpython/pulse
Code https://github.com/python/cpython
Issues https://github.com/python/cpython/issues
Pull requests https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects https://github.com/python/cpython/projects
Security https://github.com/python/cpython/security
Insights https://github.com/python/cpython/pulse
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/129867
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/129867
Support non-sequence iterables in the ExceptionGroup API, or document the design decisionhttps://github.com/python/cpython/issues/129867#top
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
type-featureA feature request or enhancementhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-feature%22
https://github.com/johnslavik
https://github.com/johnslavik
johnslavikhttps://github.com/johnslavik
on Feb 8, 2025https://github.com/python/cpython/issues/129867#issue-2840236126
via .exceptionshttps://docs.python.org/3/library/exceptions.html#BaseExceptionGroup.exceptions
other variants of this on GitHubhttps://github.com/search?q=%2FExceptionGroup%5C%28.*%2C+%28list%7Ctuple%29%5C%28%2F&type=code
cpython/Lib/test/test_exception_group.pyhttps://github.com/python/cpython/blob/1bccd6c34f82f8373c320792323bfd7f7a328bc7/Lib/test/test_exception_group.py#L39-L42
1bccd6chttps://github.com/python/cpython/commit/1bccd6c34f82f8373c320792323bfd7f7a328bc7
docs of built-in exceptionshttps://docs.python.org/3/library/exceptions.html#exception-groups
checked the PEPhttps://peps.python.org/pep-0654
the relevant PRhttps://github.com/python/cpython/pull/28569
python/exceptiongroupshttps://github.com/python/exceptiongroups
edit raise in except* example exceptiongroups#13 (comment)https://github.com/python/exceptiongroups/pull/13#issuecomment-754375503
initially plannedhttps://github.com/python/exceptiongroups/issues/6#issue-730576441
@ZeroIntensityhttps://github.com/ZeroIntensity
@Eclips4https://github.com/Eclips4
@Eclips4https://github.com/Eclips4
only causes test_bad_EG_construction__bad_excs_sequence to failhttps://pastebin.com/rg3CTLHi
@iritkatrielhttps://github.com/iritkatriel
@gvanrossumhttps://github.com/gvanrossum
@1st1https://github.com/1st1
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
type-featureA feature request or enhancementhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-feature%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.