@@ -52,7 +52,6 @@ from typing import (
52
52
SupportsInt ,
53
53
SupportsRound ,
54
54
TypeVar ,
55
- Union ,
56
55
overload ,
57
56
)
58
57
from typing_extensions import Literal , SupportsIndex , TypeGuard , final
@@ -1747,19 +1746,45 @@ if sys.version_info >= (3, 10):
1747
1746
class EncodingWarning (Warning ): ...
1748
1747
1749
1748
if sys .version_info >= (3 , 11 ):
1750
- _SplitCondition = Union [type [BaseException ], tuple [type [BaseException ], ...], Callable [[BaseException ], bool ]]
1749
+ _BaseExceptionT_co = TypeVar ("_BaseExceptionT_co" , bound = BaseException , covariant = True )
1750
+ _BaseExceptionT = TypeVar ("_BaseExceptionT" , bound = BaseException )
1751
+ _ExceptionT_co = TypeVar ("_ExceptionT_co" , bound = Exception , covariant = True )
1752
+ _ExceptionT = TypeVar ("_ExceptionT" , bound = Exception )
1751
1753
1752
- class BaseExceptionGroup (BaseException ):
1753
- def __new__ (cls : type [Self ], __message : str , __exceptions : Sequence [BaseException ]) -> Self : ...
1754
+ class BaseExceptionGroup (BaseException , Generic [ _BaseExceptionT_co ] ):
1755
+ def __new__ (cls : type [Self ], __message : str , __exceptions : Sequence [_BaseExceptionT_co ]) -> Self : ...
1754
1756
@property
1755
1757
def message (self ) -> str : ...
1756
1758
@property
1757
- def exceptions (self ) -> tuple [BaseException , ...]: ...
1758
- def subgroup (self : Self , __condition : _SplitCondition ) -> Self | None : ...
1759
- def split (self : Self , __condition : _SplitCondition ) -> tuple [Self | None , Self | None ]: ...
1760
- def derive (self : Self , __excs : Sequence [BaseException ]) -> Self : ...
1759
+ def exceptions (self ) -> tuple [_BaseExceptionT_co | BaseExceptionGroup [_BaseExceptionT_co ], ...]: ...
1760
+ @overload
1761
+ def subgroup (
1762
+ self , __condition : type [_BaseExceptionT ] | tuple [type [_BaseExceptionT ], ...]
1763
+ ) -> BaseExceptionGroup [_BaseExceptionT ] | None : ...
1764
+ @overload
1765
+ def subgroup (self : Self , __condition : Callable [[_BaseExceptionT_co ], bool ]) -> Self | None : ...
1766
+ @overload
1767
+ def split (
1768
+ self : Self , __condition : type [_BaseExceptionT ] | tuple [type [_BaseExceptionT ], ...]
1769
+ ) -> tuple [BaseExceptionGroup [_BaseExceptionT ] | None , Self | None ]: ...
1770
+ @overload
1771
+ def split (self : Self , __condition : Callable [[_BaseExceptionT_co ], bool ]) -> tuple [Self | None , Self | None ]: ...
1772
+ def derive (self : Self , __excs : Sequence [_BaseExceptionT_co ]) -> Self : ...
1761
1773
1762
- class ExceptionGroup (BaseExceptionGroup , Exception ):
1763
- def __new__ (cls : type [Self ], __message : str , __exceptions : Sequence [Exception ]) -> Self : ...
1774
+ class ExceptionGroup (BaseExceptionGroup [ _ExceptionT_co ] , Exception ):
1775
+ def __new__ (cls : type [Self ], __message : str , __exceptions : Sequence [_ExceptionT_co ]) -> Self : ...
1764
1776
@property
1765
- def exceptions (self ) -> tuple [Exception , ...]: ...
1777
+ def exceptions (self ) -> tuple [_ExceptionT_co | ExceptionGroup [_ExceptionT_co ], ...]: ...
1778
+ # We accept a narrower type, but that's OK.
1779
+ @overload # type: ignore[override]
1780
+ def subgroup (
1781
+ self , __condition : type [_ExceptionT ] | tuple [type [_ExceptionT ], ...]
1782
+ ) -> ExceptionGroup [_ExceptionT ] | None : ...
1783
+ @overload
1784
+ def subgroup (self : Self , __condition : Callable [[_ExceptionT_co ], bool ]) -> Self | None : ...
1785
+ @overload # type: ignore[override]
1786
+ def split (
1787
+ self : Self , __condition : type [_ExceptionT ] | tuple [type [_ExceptionT ], ...]
1788
+ ) -> tuple [ExceptionGroup [_ExceptionT ] | None , Self | None ]: ...
1789
+ @overload
1790
+ def split (self : Self , __condition : Callable [[_ExceptionT_co ], bool ]) -> tuple [Self | None , Self | None ]: ...
0 commit comments