@@ -22,13 +22,15 @@ from typing import (
22
22
TypeVar ,
23
23
overload ,
24
24
)
25
+ from typing_extensions import ParamSpec
25
26
from warnings import WarningMessage
26
27
27
28
if sys .version_info >= (3 , 9 ):
28
29
from types import GenericAlias
29
30
30
31
_E = TypeVar ("_E" , bound = BaseException )
31
32
_FT = TypeVar ("_FT" , bound = Callable [..., Any ])
33
+ _P = ParamSpec ("_P" )
32
34
33
35
DIFF_OMITTED : str
34
36
58
60
) -> bool | None : ...
59
61
60
62
if sys .version_info >= (3 , 8 ):
61
- def addModuleCleanup (__function : Callable [..., Any ], * args : Any , ** kwargs : Any ) -> None : ...
63
+ def addModuleCleanup (__function : Callable [_P , object ], * args : _P . args , ** kwargs : _P . kwargs ) -> None : ...
62
64
def doModuleCleanups () -> None : ...
63
65
64
66
def expectedFailure (test_item : _FT ) -> _FT : ...
@@ -106,11 +108,14 @@ class TestCase:
106
108
def assertGreaterEqual (self , a : Any , b : Any , msg : Any = ...) -> None : ...
107
109
def assertLess (self , a : Any , b : Any , msg : Any = ...) -> None : ...
108
110
def assertLessEqual (self , a : Any , b : Any , msg : Any = ...) -> None : ...
111
+ # `assertRaises`, `assertRaisesRegex`, and `assertRaisesRegexp`
112
+ # are not using `ParamSpec` intentionally,
113
+ # because they might be used with explicitly wrong arg types to raise some error in tests.
109
114
@overload
110
115
def assertRaises ( # type: ignore[misc]
111
116
self ,
112
117
expected_exception : type [BaseException ] | tuple [type [BaseException ], ...],
113
- callable : Callable [..., Any ],
118
+ callable : Callable [..., object ],
114
119
* args : Any ,
115
120
** kwargs : Any ,
116
121
) -> None : ...
@@ -121,7 +126,7 @@ class TestCase:
121
126
self ,
122
127
expected_exception : type [BaseException ] | tuple [type [BaseException ], ...],
123
128
expected_regex : str | bytes | Pattern [str ] | Pattern [bytes ],
124
- callable : Callable [..., Any ],
129
+ callable : Callable [..., object ],
125
130
* args : Any ,
126
131
** kwargs : Any ,
127
132
) -> None : ...
@@ -134,7 +139,11 @@ class TestCase:
134
139
) -> _AssertRaisesContext [_E ]: ...
135
140
@overload
136
141
def assertWarns ( # type: ignore[misc]
137
- self , expected_warning : type [Warning ] | tuple [type [Warning ], ...], callable : Callable [..., Any ], * args : Any , ** kwargs : Any
142
+ self ,
143
+ expected_warning : type [Warning ] | tuple [type [Warning ], ...],
144
+ callable : Callable [_P , object ],
145
+ * args : _P .args ,
146
+ ** kwargs : _P .kwargs ,
138
147
) -> None : ...
139
148
@overload
140
149
def assertWarns (self , expected_warning : type [Warning ] | tuple [type [Warning ], ...], msg : Any = ...) -> _AssertWarnsContext : ...
@@ -143,9 +152,9 @@ class TestCase:
143
152
self ,
144
153
expected_warning : type [Warning ] | tuple [type [Warning ], ...],
145
154
expected_regex : str | bytes | Pattern [str ] | Pattern [bytes ],
146
- callable : Callable [..., Any ],
147
- * args : Any ,
148
- ** kwargs : Any ,
155
+ callable : Callable [_P , object ],
156
+ * args : _P . args ,
157
+ ** kwargs : _P . kwargs ,
149
158
) -> None : ...
150
159
@overload
151
160
def assertWarnsRegex (
@@ -207,13 +216,13 @@ class TestCase:
207
216
def id (self ) -> str : ...
208
217
def shortDescription (self ) -> str | None : ...
209
218
if sys .version_info >= (3 , 8 ):
210
- def addCleanup (self , __function : Callable [..., Any ], * args : Any , ** kwargs : Any ) -> None : ...
219
+ def addCleanup (self , __function : Callable [_P , object ], * args : _P . args , ** kwargs : _P . kwargs ) -> None : ...
211
220
else :
212
- def addCleanup (self , function : Callable [..., Any ], * args : Any , ** kwargs : Any ) -> None : ...
221
+ def addCleanup (self , function : Callable [_P , object ], * args : _P . args , ** kwargs : _P . kwargs ) -> None : ...
213
222
def doCleanups (self ) -> None : ...
214
223
if sys .version_info >= (3 , 8 ):
215
224
@classmethod
216
- def addClassCleanup (cls , __function : Callable [..., Any ], * args : Any , ** kwargs : Any ) -> None : ...
225
+ def addClassCleanup (cls , __function : Callable [_P , object ], * args : _P . args , ** kwargs : _P . kwargs ) -> None : ...
217
226
@classmethod
218
227
def doClassCleanups (cls ) -> None : ...
219
228
def _formatMessage (self , msg : str | None , standardMsg : str ) -> str : ... # undocumented
@@ -230,9 +239,9 @@ class TestCase:
230
239
def failUnlessRaises ( # type: ignore[misc]
231
240
self ,
232
241
exception : type [BaseException ] | tuple [type [BaseException ], ...],
233
- callable : Callable [..., Any ] = ...,
234
- * args : Any ,
235
- ** kwargs : Any ,
242
+ callable : Callable [_P , object ] = ...,
243
+ * args : _P . args ,
244
+ ** kwargs : _P . kwargs ,
236
245
) -> None : ...
237
246
@overload
238
247
def failUnlessRaises (self , exception : type [_E ] | tuple [type [_E ], ...], msg : Any = ...) -> _AssertRaisesContext [_E ]: ...
@@ -251,7 +260,7 @@ class TestCase:
251
260
self ,
252
261
exception : type [BaseException ] | tuple [type [BaseException ], ...],
253
262
expected_regex : str | bytes | Pattern [str ] | Pattern [bytes ],
254
- callable : Callable [..., Any ],
263
+ callable : Callable [..., object ],
255
264
* args : Any ,
256
265
** kwargs : Any ,
257
266
) -> None : ...
0 commit comments