René's URL Explorer Experiment


Title: Introducing try..except* · Issue #4 · python/exceptiongroups · GitHub

Open Graph Title: Introducing try..except* · Issue #4 · python/exceptiongroups

X Title: Introducing try..except* · Issue #4 · python/exceptiongroups

Description: The design discussed in this issue has been consolidated in https://github.com/python/exceptiongroups/blob/master/except_star.md. Disclaimer I'm going to be using the ExceptionGroup name in this issue, even though there are other alterna...

Open Graph Description: The design discussed in this issue has been consolidated in https://github.com/python/exceptiongroups/blob/master/except_star.md. Disclaimer I'm going to be using the ExceptionGroup name in this is...

X Description: The design discussed in this issue has been consolidated in https://github.com/python/exceptiongroups/blob/master/except_star.md. Disclaimer I'm going to be using the ExceptionGroup name in thi...

Opengraph URL: https://github.com/python/exceptiongroups/issues/4

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Introducing try..except*","articleBody":"### The design discussed in this issue has been consolidated in https://github.com/python/exceptiongroups/blob/master/except_star.md.\r\n\r\n-----\r\n\r\n### Disclaimer\r\n\r\n* I'm going to be using the `ExceptionGroup` name in this issue, even though there are other alternatives, e.g. `AggregateException`. Naming of the \"exception group\" object is outside of the scope of this issue.\r\n* This issue is primarily focused on discussing the new syntax modification proposal for the `try..except` construct, shortly called \"except*\".\r\n* I use the term \"naked\" exception for regular Python exceptions **not wrapped** in an ExceptionGroup. E.g. a regular `ValueError` propagating through the stack is \"naked\".\r\n* I assume that `ExceptionGroup` would be an iterable object. E.g. `list(ExceptionGroup(ValueError('a'), TypeError('b')))` would be equal to `[ValueError('a'), TypeError('b')]`\r\n* I assume that `ExceptionGroup` won't be an indexable object; essentially it's similar to Python `set`. The motivation for this is that exceptions can occur in random order, and letting users write `group[0]` to access the \"first\" error is error prone. The actual implementation of `ExceptionGroup` will likely use an ordered list of errors though.\r\n* I assume that `ExceptionGroup` will be a subclass of `BaseException`, which means it's assignable to `Exception.__context__` and can be directly handled with `except ExceptionGroup`.\r\n* The behavior of good and old regular `try..except` will not be modified.\r\n\r\n### Syntax\r\n\r\nWe're considering to introduce a new variant of the `try..except` syntax to simplify working with exception groups:\r\n\r\n```python\r\ntry:\r\n  ...\r\nexcept *SpamError:\r\n  ...\r\nexcept *BazError as e:\r\n  ...\r\nexcept *(BarError, FooError) as e:\r\n  ...\r\n```\r\n\r\nThe new syntax can be viewed as a variant of the tuple unpacking syntax. The `*` symbol indicates that zero or more exceptions can be \"caught\" and processed by one `except *` clause.\r\n\r\nWe also propose to enable \"unpacking\" in the `raise` statement:\r\n\r\n```python\r\nerrors = (ValueError('hello'), TypeError('world'))\r\nraise *errors\r\n```\r\n\r\n### Semantics\r\n\r\n#### Overview\r\n\r\nThe  `except *SpamError` block will be run if the `try` code raised an `ExceptionGroup` with one or more instances of `SpamError`. It would also be triggered if a naked instance of  `SpamError` was raised.\r\n\r\nThe `except *BazError as e` block would aggregate all instances of `BazError`  into a list, wrap that list into an `ExceptionGroup` instance, and assign the resultant object to `e`. The type of `e` would be `ExceptionGroup[BazError]`.  If there was just one naked instance of `BazError`, it would be wrapped into a list and assigned to `e`.\r\n\r\nThe `except *(BarError, FooError) as e` would aggregate all instances of `BarError` or `FooError`  into a list and assign that wrapped list to `e`. The type of `e` would be `ExceptionGroup[Union[BarError, FooError]]`.\r\n\r\nEven though every `except*` star can be called only once, any number of them can be run during handling of an `ExceptionGroup`. E.g. in the above example,  both `except *SpamError:` and `except *(BarError, FooError) as e:` could get executed during handling of one `ExceptionGroup` object, or all of the `except*` clauses, or just one of them.\r\n\r\nIt is not allowed to use both regular `except` clauses and the new `except*` clauses in the same `try` block. E.g. the following example would raise a `SyntaxErorr`:\r\n\r\n```python\r\ntry:\r\n   ...\r\nexcept ValueError:\r\n   pass\r\nexcept *CancelledError:\r\n   pass\r\n```\r\n\r\nExceptions are mached using a subclass check. For example:\r\n\r\n```python\r\ntry:\r\n  low_level_os_operation()\r\nexcept *OSerror as errors:\r\n  for e in errors:\r\n    print(type(e).__name__)\r\n```\r\n\r\ncould output:\r\n\r\n```\r\nBlockingIOError\r\nConnectionRefusedError\r\nOSError\r\nInterruptedError\r\nBlockingIOError\r\n```\r\n\r\n#### New raise* Syntax\r\n\r\nThe new  `raise *` syntax allows to users to only process some exceptions out of the matched set, e.g.:\r\n\r\n```python\r\ntry:\r\n  low_level_os_operation()\r\nexcept *OSerror as errors:\r\n  new_errors = []\r\n  for e in errors:\r\n    if e.errno != errno.EPIPE:\r\n       new_errors.append(e)\r\n  raise *new_errors\r\n```\r\n\r\nThe above code ignores all `EPIPE` OS errors, while letting all others propagate.\r\n\r\n`raise *` syntax is special: it effectively extends the exception group with a list of errors without creating a new `ExceptionGroup` instance:\r\n\r\n```python\r\ntry:\r\n  raise *(ValueError('a'), TypeError('b'))\r\nexcept *ValueError:\r\n  raise *(KeyError('x'), KeyError('y'))\r\n\r\n# would result in: \r\n#   ExceptionGroup({KeyError('x'), KeyError('y'), TypeError('b')})\r\n```\r\n\r\nA regular raise would behave similarly:\r\n\r\n```python\r\ntry:\r\n  raise *(ValueError('a'), TypeError('b'))\r\nexcept *ValueError:\r\n  raise KeyError('x')\r\n\r\n# would result in: \r\n#   ExceptionGroup({KeyError('x'), TypeError('b')})\r\n```\r\n\r\n`raise *` accepts arguments of type `Iterable[BaseException]`.\r\n\r\n#### Unmatched Exceptions\r\n\r\nExample:\r\n\r\n```python\r\ntry:\r\n  raise *(ValueError('a'), TypeError('b'), TypeError('c'), KeyError('e'))\r\nexcept *ValueError as e:\r\n  print(f'got some ValueErrors: {e}')\r\nexcept *TypeError as e:\r\n  print(f'got some TypeErrors: {e}')\r\n  raise *e\r\n```\r\n\r\nThe above code would print:\r\n\r\n```\r\ngot some ValueErrors: ExceptionGroup({ValueError('a')})\r\ngot some TypeErrors: ExceptionGroup({TypeError('b'), TypeError('c')})\r\n```\r\n\r\nAnd then crash with an unhandled `KeyError('e')` error.\r\n\r\nBasically, before interpreting `except *` clauses, the interpreter will have an exception group object with a list of exceptions in it. Every `except *` clause, evaluated from top to bottom, can filter some of the exceptions out of the group and process them. In the end, if the exception group has no exceptions left in it, it wold mean that all exceptions were processed. If the exception group has some unprocessed exceptions, the current frame will be \"pushed\" to the group's traceback and the group would be propagated up the stack.\r\n\r\n#### Exception Chaining\r\n\r\nIf an error occur during processing a set of exceptions in a `except *` block, all matched errors would be put in a new `ExceptionGroup` which would have its `__context__` attribute set to the just occurred exception:\r\n\r\n```python\r\ntry:\r\n  raise *(ValueError('a'), ValueError('b'), TypeError('z'))\r\nexcept *ValueError:\r\n  1 / 0\r\n\r\n# would result in:\r\n#\r\n#   ExceptionGroup({\r\n#     TypeError('z'),\r\n#     ZeroDivisionError()\r\n#   })\r\n#\r\n# where the `ZeroDivizionError()` instance would have\r\n# its __context__ attribute set to\r\n#\r\n#   ExceptionGroup({\r\n#     ValueError('a'), ValueError('b')\r\n#   })\r\n```\r\n\r\nIt's also possible to explicitly chain exceptions:\r\n\r\n```python\r\ntry:\r\n  raise *(ValueError('a'), ValueError('b'), TypeError('z'))\r\nexcept *ValueError as errors:\r\n  raise RuntimeError('unexpected values') from errors\r\n\r\n# would result in:\r\n#\r\n#   ExceptionGroup(\r\n#     TypeError('z'),\r\n#     RuntimeError('unexpected values')\r\n#   )\r\n#\r\n# where the `RuntimeError()` instance would have\r\n# its __cause__ attribute set to\r\n#\r\n#   ExceptionGroup({\r\n#     ValueError('a'), ValueError('b')\r\n#   })\r\n```\r\n\r\n### See Also\r\n\r\n* An analysis of how exception groups will likely be used in asyncio programs: https://github.com/python/exceptiongroups/issues/3#issuecomment-716203284\r\n* A WIP  implementation of the `ExceptionGroup` type by @iritkatriel tracked here: [GitHub - iritkatriel/cpython at exceptionGroup](https://github.com/iritkatriel/cpython/tree/exceptionGroup)\r\n","author":{"url":"https://github.com/1st1","@type":"Person","name":"1st1"},"datePublished":"2020-10-26T02:41:23.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":13},"url":"https://github.com/4/exceptiongroups/issues/4"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:fb922919-6b05-a690-a4a8-b976dea590aa
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idB608:7F615:AFED3A:ECF90F:696996F0
html-safe-noncec2acfdb8106d2d4c6653bacbce7aad95537714c630eeafc0beba38a85d4f8e05
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNjA4OjdGNjE1OkFGRUQzQTpFQ0Y5MEY6Njk2OTk2RjAiLCJ2aXNpdG9yX2lkIjoiNTU2NTA5NzIxODYzNzY2NjAzMiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac92ca7d5431f807bb90b93b480ad31dff7df3cc6a067795e222c8b4f25016ea0e
hovercard-subject-tagissue:729190689
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/exceptiongroups/4/issue_layout
twitter:imagehttps://opengraph.githubassets.com/93f3ca33cbb58c031cf16516413352138f4b70b4020918029e1cbd1928168a77/python/exceptiongroups/issues/4
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/93f3ca33cbb58c031cf16516413352138f4b70b4020918029e1cbd1928168a77/python/exceptiongroups/issues/4
og:image:altThe design discussed in this issue has been consolidated in https://github.com/python/exceptiongroups/blob/master/except_star.md. Disclaimer I'm going to be using the ExceptionGroup name in this is...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:username1st1
hostnamegithub.com
expected-hostnamegithub.com
None3542e147982176a7ebaa23dfb559c8af16f721c03ec560c68c56b64a0f35e751
turbo-cache-controlno-preview
go-importgithub.com/python/exceptiongroups git https://github.com/python/exceptiongroups.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id228462148
octolytics-dimension-repository_nwopython/exceptiongroups
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id228462148
octolytics-dimension-repository_network_root_nwopython/exceptiongroups
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
releaseaf80af7cc9e3de9c336f18b208a600950a3c187c
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/exceptiongroups/issues/4#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fexceptiongroups%2Fissues%2F4
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%2Fexceptiongroups%2Fissues%2F4
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%2Fexceptiongroups
Reloadhttps://github.com/python/exceptiongroups/issues/4
Reloadhttps://github.com/python/exceptiongroups/issues/4
Reloadhttps://github.com/python/exceptiongroups/issues/4
python https://github.com/python
exceptiongroupshttps://github.com/python/exceptiongroups
Notifications https://github.com/login?return_to=%2Fpython%2Fexceptiongroups
Fork 2 https://github.com/login?return_to=%2Fpython%2Fexceptiongroups
Star 21 https://github.com/login?return_to=%2Fpython%2Fexceptiongroups
Code https://github.com/python/exceptiongroups
Issues 2 https://github.com/python/exceptiongroups/issues
Pull requests 0 https://github.com/python/exceptiongroups/pulls
Actions https://github.com/python/exceptiongroups/actions
Projects 0 https://github.com/python/exceptiongroups/projects
Security Uh oh! There was an error while loading. Please reload this page. https://github.com/python/exceptiongroups/security
Please reload this pagehttps://github.com/python/exceptiongroups/issues/4
Insights https://github.com/python/exceptiongroups/pulse
Code https://github.com/python/exceptiongroups
Issues https://github.com/python/exceptiongroups/issues
Pull requests https://github.com/python/exceptiongroups/pulls
Actions https://github.com/python/exceptiongroups/actions
Projects https://github.com/python/exceptiongroups/projects
Security https://github.com/python/exceptiongroups/security
Insights https://github.com/python/exceptiongroups/pulse
Introducing try..except*https://github.com/python/exceptiongroups/issues/4#top
https://github.com/1st1
https://github.com/1st1
1st1https://github.com/1st1
on Oct 26, 2020https://github.com/python/exceptiongroups/issues/4#issue-729190689
https://github.com/python/exceptiongroups/blob/master/except_star.mdhttps://github.com/python/exceptiongroups/blob/master/except_star.md
Introducing try..catch #3 (comment)https://github.com/python/exceptiongroups/issues/3#issuecomment-716203284
@iritkatrielhttps://github.com/iritkatriel
GitHub - iritkatriel/cpython at exceptionGrouphttps://github.com/iritkatriel/cpython/tree/exceptionGroup
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.