Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BaseExceptionGroup should return ExceptionGroup if initialized with non-base exceptions #12972

Open
jakkdl opened this issue Nov 7, 2024 · 1 comment

Comments

@jakkdl
Copy link

jakkdl commented Nov 7, 2024

When initializing a BaseExceptionGroup with non-base exceptions the stdlib (and the backport) will in fact return an ExceptionGroup. The typing in neither of typeshed nor the backport currently supports this.

from typing_extensions import reveal_type

x = BaseExceptionGroup('', [ValueError()])
reveal_type(x)
$ python foo.py
Runtime type is 'ExceptionGroup'
$ mypy foo.py 
foo.py:30: note: Revealed type is "builtins.BaseExceptionGroup[builtins.ValueError]"
$ pyright foo.py 
foo.py
  foo.py:30:13 - information: Type of "x" is "BaseExceptionGroup[ValueError]"

I have vague recollections that trying to do this was hard-to-impossible, but I currently cannot find any related issues.

@brianschubert
Copy link
Contributor

Somewhat related: #9922

At a glance it seems like an overloaded __new__ might work, similar to what's done with some of the other BaseExceptionGroup methods. Though given how special __new__ is, I suspect there may be some unique complications

(cc @sobolevn as the author of the current BaseExceptionGroup overloads)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants