mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-10 05:51:52 +08:00
ExceptionGroup: make it generic (#7626)
This commit is contained in:
@@ -52,7 +52,6 @@ from typing import (
|
||||
SupportsInt,
|
||||
SupportsRound,
|
||||
TypeVar,
|
||||
Union,
|
||||
overload,
|
||||
)
|
||||
from typing_extensions import Literal, SupportsIndex, TypeGuard, final
|
||||
@@ -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]: ...
|
||||
|
||||
Reference in New Issue
Block a user