1
1
import builtins
2
2
import unittest .mock
3
- from typing import cast , Generator , Mapping , Iterable , Tuple
3
+ from typing import cast , overload , Generator , Mapping , Iterable , Tuple , TypeVar
4
4
from typing import Any
5
5
from typing import Callable
6
6
from typing import Dict
17
17
18
18
import pytest
19
19
20
+ _T = TypeVar ("_T" )
21
+
20
22
21
23
def _get_mock_module (config ):
22
24
"""
@@ -50,7 +52,9 @@ def __init__(self, config: Any) -> None:
50
52
self ._patches = [] # type: List[Any]
51
53
self ._mocks = [] # type: List[Any]
52
54
self .mock_module = mock_module = _get_mock_module (config )
53
- self .patch = self ._Patcher (self ._patches , self ._mocks , mock_module )
55
+ self .patch = self ._Patcher (
56
+ self ._patches , self ._mocks , mock_module
57
+ ) # type: MockerFixture._Patcher
54
58
# aliases for convenience
55
59
self .Mock = mock_module .Mock
56
60
self .MagicMock = mock_module .MagicMock
@@ -254,6 +258,63 @@ def dict(
254
258
** kwargs
255
259
)
256
260
261
+ @overload
262
+ def __call__ (
263
+ self ,
264
+ target : str ,
265
+ new : None = ...,
266
+ spec : Optional [builtins .object ] = ...,
267
+ create : bool = ...,
268
+ spec_set : Optional [builtins .object ] = ...,
269
+ autospec : Optional [builtins .object ] = ...,
270
+ new_callable : None = ...,
271
+ ** kwargs : Any
272
+ ) -> unittest .mock .MagicMock :
273
+ ...
274
+
275
+ @overload
276
+ def __call__ (
277
+ self ,
278
+ target : str ,
279
+ new : _T ,
280
+ spec : Optional [builtins .object ] = ...,
281
+ create : bool = ...,
282
+ spec_set : Optional [builtins .object ] = ...,
283
+ autospec : Optional [builtins .object ] = ...,
284
+ new_callable : None = ...,
285
+ ** kwargs : Any
286
+ ) -> _T :
287
+ ...
288
+
289
+ @overload
290
+ def __call__ (
291
+ self ,
292
+ target : str ,
293
+ new : None ,
294
+ spec : Optional [builtins .object ],
295
+ create : bool ,
296
+ spec_set : Optional [builtins .object ],
297
+ autospec : Optional [builtins .object ],
298
+ new_callable : Callable [[], _T ],
299
+ ** kwargs : Any
300
+ ) -> _T :
301
+ ...
302
+
303
+ @overload
304
+ def __call__ (
305
+ self ,
306
+ target : str ,
307
+ new : None = ...,
308
+ spec : Optional [builtins .object ] = ...,
309
+ create : bool = ...,
310
+ spec_set : Optional [builtins .object ] = ...,
311
+ autospec : Optional [builtins .object ] = ...,
312
+ * ,
313
+ new_callable : Callable [[], _T ],
314
+ ** kwargs : Any
315
+ ) -> _T :
316
+ ...
317
+
257
318
def __call__ (
258
319
self ,
259
320
target : str ,
@@ -262,9 +323,9 @@ def __call__(
262
323
create : bool = False ,
263
324
spec_set : Optional [builtins .object ] = None ,
264
325
autospec : Optional [builtins .object ] = None ,
265
- new_callable : Optional [builtins . object ] = None ,
326
+ new_callable : Optional [Callable [[], Any ] ] = None ,
266
327
** kwargs : Any
267
- ) -> unittest . mock . MagicMock :
328
+ ) -> Any :
268
329
"""API to mock.patch"""
269
330
if new is self .DEFAULT :
270
331
new = self .mock_module .DEFAULT
0 commit comments