Skip to content

Commit

Permalink
ExceptionGroup: make it generic (#7626)
Browse files Browse the repository at this point in the history
  • Loading branch information
JelleZijlstra authored Apr 15, 2022
1 parent 7f9be7f commit e0654bd
Showing 1 changed file with 36 additions and 11 deletions.
47 changes: 36 additions & 11 deletions stdlib/builtins.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ from typing import (
SupportsInt,
SupportsRound,
TypeVar,
Union,
overload,
)
from typing_extensions import Literal, SupportsIndex, TypeGuard, final
Expand Down Expand Up @@ -1747,19 +1746,45 @@ if sys.version_info >= (3, 10):
class EncodingWarning(Warning): ...

if sys.version_info >= (3, 11):
_SplitCondition = Union[type[BaseException], tuple[type[BaseException], ...], Callable[[BaseException], bool]]
_BaseExceptionT_co = TypeVar("_BaseExceptionT_co", bound=BaseException, covariant=True)
_BaseExceptionT = TypeVar("_BaseExceptionT", bound=BaseException)
_ExceptionT_co = TypeVar("_ExceptionT_co", bound=Exception, covariant=True)
_ExceptionT = TypeVar("_ExceptionT", bound=Exception)

class BaseExceptionGroup(BaseException):
def __new__(cls: type[Self], __message: str, __exceptions: Sequence[BaseException]) -> Self: ...
class BaseExceptionGroup(BaseException, Generic[_BaseExceptionT_co]):
def __new__(cls: type[Self], __message: str, __exceptions: Sequence[_BaseExceptionT_co]) -> Self: ...
@property
def message(self) -> str: ...
@property
def exceptions(self) -> tuple[BaseException, ...]: ...
def subgroup(self: Self, __condition: _SplitCondition) -> Self | None: ...
def split(self: Self, __condition: _SplitCondition) -> tuple[Self | None, Self | None]: ...
def derive(self: Self, __excs: Sequence[BaseException]) -> Self: ...
def exceptions(self) -> tuple[_BaseExceptionT_co | BaseExceptionGroup[_BaseExceptionT_co], ...]: ...
@overload
def subgroup(
self, __condition: type[_BaseExceptionT] | tuple[type[_BaseExceptionT], ...]
) -> BaseExceptionGroup[_BaseExceptionT] | None: ...
@overload
def subgroup(self: Self, __condition: Callable[[_BaseExceptionT_co], bool]) -> Self | None: ...
@overload
def split(
self: Self, __condition: type[_BaseExceptionT] | tuple[type[_BaseExceptionT], ...]
) -> tuple[BaseExceptionGroup[_BaseExceptionT] | None, Self | None]: ...
@overload
def split(self: Self, __condition: Callable[[_BaseExceptionT_co], bool]) -> tuple[Self | None, Self | None]: ...
def derive(self: Self, __excs: Sequence[_BaseExceptionT_co]) -> Self: ...

class ExceptionGroup(BaseExceptionGroup, Exception):
def __new__(cls: type[Self], __message: str, __exceptions: Sequence[Exception]) -> Self: ...
class ExceptionGroup(BaseExceptionGroup[_ExceptionT_co], Exception):
def __new__(cls: type[Self], __message: str, __exceptions: Sequence[_ExceptionT_co]) -> Self: ...
@property
def exceptions(self) -> tuple[Exception, ...]: ...
def exceptions(self) -> tuple[_ExceptionT_co | ExceptionGroup[_ExceptionT_co], ...]: ...
# We accept a narrower type, but that's OK.
@overload # type: ignore[override]
def subgroup(
self, __condition: type[_ExceptionT] | tuple[type[_ExceptionT], ...]
) -> ExceptionGroup[_ExceptionT] | None: ...
@overload
def subgroup(self: Self, __condition: Callable[[_ExceptionT_co], bool]) -> Self | None: ...
@overload # type: ignore[override]
def split(
self: Self, __condition: type[_ExceptionT] | tuple[type[_ExceptionT], ...]
) -> tuple[ExceptionGroup[_ExceptionT] | None, Self | None]: ...
@overload
def split(self: Self, __condition: Callable[[_ExceptionT_co], bool]) -> tuple[Self | None, Self | None]: ...

0 comments on commit e0654bd

Please sign in to comment.