typeshed icon indicating copy to clipboard operation
typeshed copied to clipboard

Default type for built-in ExceptionGroup

Open machadinhos opened this issue 1 year ago • 0 comments

Hi,

I've ran into this issue with pyright: Input:

def a() -> None:
    ex: ExceptionGroup[ValueError] = ExceptionGroup("", [ValueError("a"), ValueError("b")])
    raise ex

try:
    a()
except ExceptionGroup as e:
    print(all(isinstance(exc, ValueError) for exc in e.exceptions))

pyright error:

test.py:8:26 - error: Type of "e" is partially unknown
    Type of "e" is "ExceptionGroup[Unknown]" (reportUnknownVariableType)

After talking to @erictraut, he directed me here to propose the built-in ExceptionGroup to have Exeception has a default type.

Here is the pyright discussion.

Here are his quotes:

With PEP 696 now officially accepted, the maintainers of typeshed could specify that the type parameter for ExceptionGroup defaults to Exception. In that case, pyright will no longer assume Unknown in this case. If that sounds like a good solution, please file a request (or submit a PR) in the typeshed project.

and

The change would involve a change to this line.

I'm not sure on how to make the changes my self and I don't even know if they should be made at all.

Thanks a lot!

machadinhos avatar Jul 01 '24 00:07 machadinhos