Title: [question] Proper way to implement `ExceptionGroup.derive` method with the existing overloads? · Issue #9922 · python/typeshed · GitHub
Open Graph Title: [question] Proper way to implement `ExceptionGroup.derive` method with the existing overloads? · Issue #9922 · python/typeshed
X Title: [question] Proper way to implement `ExceptionGroup.derive` method with the existing overloads? · Issue #9922 · python/typeshed
Description: Good afternoon, I was working to implement some custom exception groups in an application that I work on and have had a really hard time getting the types for the derive function to work correctly. Based on reading the documentation link...
Open Graph Description: Good afternoon, I was working to implement some custom exception groups in an application that I work on and have had a really hard time getting the types for the derive function to work correctly....
X Description: Good afternoon, I was working to implement some custom exception groups in an application that I work on and have had a really hard time getting the types for the derive function to work correctly....
Opengraph URL: https://github.com/python/typeshed/issues/9922
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[question] Proper way to implement `ExceptionGroup.derive` method with the existing overloads?","articleBody":"Good afternoon,\r\n\r\nI was working to implement some custom exception groups in an application that I work on and have had a really hard time getting the types for the `derive` function to work correctly. Based on reading the documentation linked below, `derive` is a required method when overriding an exception group to return an instance of it's own class.\r\n\r\n## Reference\r\nhttps://docs.python.org/3/library/exceptions.html#BaseExceptionGroup.derive\r\n\r\n## Reproduction / Example\r\nTo reproduce this error, I'll use the example shows in the BaseExceptionGroup page, but with type hints:\r\n\r\n```python\r\nfrom __future__ import annotations\r\n\r\nfrom collections.abc import Sequence\r\nfrom typing import TypeVar\r\n\r\n_ExceptionT_co = TypeVar(\"_ExceptionT_co\", bound=Exception, covariant=True)\r\n_ExceptionT = TypeVar(\"_ExceptionT\", bound=Exception)\r\n\r\n\r\nclass MyGroup(ExceptionGroup[_ExceptionT_co]):\r\n def derive(self, excs: Sequence[_ExceptionT]) -> MyGroup[_ExceptionT]:\r\n return MyGroup(self.message, excs)\r\n```\r\n\r\nMypy output:\r\n\r\n```\r\n❯ mypy ~/Desktop/example.py\r\n/Users/kkirsche/Desktop/example.py:11: error: Signature of \"derive\" incompatible with supertype \"BaseExceptionGroup\" [override]\r\n/Users/kkirsche/Desktop/example.py:11: note: Superclass:\r\n/Users/kkirsche/Desktop/example.py:11: note: @overload\r\n/Users/kkirsche/Desktop/example.py:11: note: def [_ExceptionT \u003c: Exception] derive(self, Sequence[_ExceptionT], /) -> ExceptionGroup[_ExceptionT]\r\n/Users/kkirsche/Desktop/example.py:11: note: @overload\r\n/Users/kkirsche/Desktop/example.py:11: note: def [_BaseExceptionT \u003c: BaseException] derive(self, Sequence[_BaseExceptionT], /) -> BaseExceptionGroup[_BaseExceptionT]\r\n/Users/kkirsche/Desktop/example.py:11: note: Subclass:\r\n/Users/kkirsche/Desktop/example.py:11: note: def [_ExceptionT \u003c: Exception] derive(self, excs: Sequence[_ExceptionT]) -> MyGroup[_ExceptionT]\r\nFound 1 error in 1 file (checked 1 source file)\r\n```\r\n\r\nGiven that this is working off an exception group rather than a base exception group, I'm unclear on what the proper way to fix this would be and was wondering if the team here was able to provide an example that satisfies mypy / typeshed's overrides for `BaseExceptionGroup`'s `derive` function.\r\n\r\n## Thoughts\r\n\r\nWould it potentially make sense to add a derive method to `ExceptionGroup` which returns `Self` rather than a hardcoded `ExceptionGroup`? This seems to align with how the documentation describes using this behavior, but I'm not confident I understand fully to submit a pull request with recommended change(s).\r\n\r\nThanks for your time and help, hope you all are having a great day.","author":{"url":"https://github.com/kkirsche","@type":"Person","name":"kkirsche"},"datePublished":"2023-03-22T17:54:38Z","url":"https://github.com/python/typeshed/issues/9922"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| 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:05410c06-06a2-a678-72f0-9f27a2c5e2ba |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C738:3A13A0:23E3506:30B3CBE:6B002F6B |
| html-safe-nonce | 95fdb8e352f49922e301510074a92d9c7aa117a4c99bc8296e7a351f907cf93a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNzM4OjNBMTNBMDoyM0UzNTA2OjMwQjNDQkU6NkIwMDJGNkIiLCJ2aXNpdG9yX2lkIjoiNTYwMzcxNjM2NjI5NDA2OTA5OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | fda7f9959d1a762f873d0a6a2663441374f2e351075596d901cd328ac967f7ea |
| hovercard-subject-tag | issue:1636244902 |
| 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/typeshed/9922/issue_layout |
| twitter:image | https://opengraph.githubassets.com/eb85efb3e877f795843cf6b8cf97107c7e348577a86da82b3acabafc5f0658cd/python/typeshed/issues/9922 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/eb85efb3e877f795843cf6b8cf97107c7e348577a86da82b3acabafc5f0658cd/python/typeshed/issues/9922 |
| og:image:alt | Good afternoon, I was working to implement some custom exception groups in an application that I work on and have had a really hard time getting the types for the derive function to work correctly.... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | kkirsche |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7d0829bbde9e48b2486cb5dd6d147896eb01d32134627091f818958a935ef3f0 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/typeshed git https://github.com/python/typeshed.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 31696383 |
| octolytics-dimension-repository_nwo | python/typeshed |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 31696383 |
| octolytics-dimension-repository_network_root_nwo | python/typeshed |
| 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 | f3f3a43ca095cdea3abbb394112e971f9fdb94fa |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width