@@ -3,8 +3,8 @@ import sys
3
3
from _warnings import warn as warn , warn_explicit as warn_explicit
4
4
from collections .abc import Sequence
5
5
from types import ModuleType , TracebackType
6
- from typing import Any , Generic , Literal , TextIO , TypeVar , overload
7
- from typing_extensions import LiteralString , TypeAlias
6
+ from typing import Any , Generic , Literal , TextIO , overload
7
+ from typing_extensions import LiteralString , TypeAlias , TypeVar
8
8
9
9
__all__ = [
10
10
"warn" ,
@@ -21,7 +21,8 @@ if sys.version_info >= (3, 13):
21
21
__all__ += ["deprecated" ]
22
22
23
23
_T = TypeVar ("_T" )
24
- _W = TypeVar ("_W" , bound = list [WarningMessage ] | None )
24
+ _W_co = TypeVar ("_W_co" , bound = list [WarningMessage ] | None , default = list [WarningMessage ] | None , covariant = True )
25
+
25
26
if sys .version_info >= (3 , 14 ):
26
27
_ActionKind : TypeAlias = Literal ["default" , "error" , "ignore" , "always" , "module" , "once" ]
27
28
else :
@@ -66,7 +67,7 @@ class WarningMessage:
66
67
source : Any | None = None ,
67
68
) -> None : ...
68
69
69
- class catch_warnings (Generic [_W ]):
70
+ class catch_warnings (Generic [_W_co ]):
70
71
if sys .version_info >= (3 , 11 ):
71
72
@overload
72
73
def __init__ (
@@ -92,7 +93,7 @@ class catch_warnings(Generic[_W]):
92
93
) -> None : ...
93
94
@overload
94
95
def __init__ (
95
- self : catch_warnings [ list [ WarningMessage ] | None ] ,
96
+ self ,
96
97
* ,
97
98
record : bool ,
98
99
module : ModuleType | None = None ,
@@ -109,11 +110,9 @@ class catch_warnings(Generic[_W]):
109
110
self : catch_warnings [list [WarningMessage ]], * , record : Literal [True ], module : ModuleType | None = None
110
111
) -> None : ...
111
112
@overload
112
- def __init__ (
113
- self : catch_warnings [list [WarningMessage ] | None ], * , record : bool , module : ModuleType | None = None
114
- ) -> None : ...
113
+ def __init__ (self , * , record : bool , module : ModuleType | None = None ) -> None : ...
115
114
116
- def __enter__ (self ) -> _W : ...
115
+ def __enter__ (self ) -> _W_co : ...
117
116
def __exit__ (
118
117
self , exc_type : type [BaseException ] | None , exc_val : BaseException | None , exc_tb : TracebackType | None
119
118
) -> None : ...
0 commit comments