11from _typeshed import Self
2- from collections .abc import Awaitable , Callable , Mapping , Sequence
2+ from collections .abc import Callable , Coroutine , Mapping , Sequence
33from contextlib import AbstractContextManager
44from types import TracebackType
55from typing import Any , Generic , TypeVar , overload
66from typing_extensions import Literal
77
88_F = TypeVar ("_F" , bound = Callable [..., Any ])
9- _AF = TypeVar ("_AF" , bound = Callable [..., Awaitable [ Any ]])
9+ _AF = TypeVar ("_AF" , bound = Callable [..., Coroutine [ Any , Any , Any ]])
1010_T = TypeVar ("_T" )
1111_TT = TypeVar ("_TT" , bound = type [Any ])
1212_R = TypeVar ("_R" )
@@ -28,12 +28,20 @@ __all__ = (
2828 "PropertyMock" ,
2929 "seal" ,
3030)
31- __version__ : str
3231
33- FILTER_DIR : Any
32+ class InvalidSpecError ( Exception ): ...
3433
35- sentinel : Any
36- DEFAULT : Any
34+ FILTER_DIR : bool
35+
36+ class _SentinelObject :
37+ def __init__ (self , name : str ) -> None : ...
38+ name : str
39+
40+ class _Sentinel :
41+ def __getattr__ (self , name : str ) -> _SentinelObject : ...
42+
43+ sentinel : _Sentinel
44+ DEFAULT : _SentinelObject
3745
3846class _Call (tuple [Any , ...]):
3947 def __new__ (
@@ -69,7 +77,21 @@ class Base:
6977 def __init__ (self , * args : Any , ** kwargs : Any ) -> None : ...
7078
7179class NonCallableMock (Base , Any ):
72- def __new__ (__cls : type [Self ], * args : Any , ** kw : Any ) -> Self : ...
80+ def __new__ (
81+ cls : type [Self ],
82+ spec : list [str ] | object | type [object ] | None = ...,
83+ wraps : Any | None = ...,
84+ name : str | None = ...,
85+ spec_set : list [str ] | object | type [object ] | None = ...,
86+ parent : NonCallableMock | None = ...,
87+ _spec_state : Any | None = ...,
88+ _new_name : str = ...,
89+ _new_parent : NonCallableMock | None = ...,
90+ _spec_as_instance : bool = ...,
91+ _eat_self : bool | None = ...,
92+ unsafe : bool = ...,
93+ ** kwargs : Any ,
94+ ) -> Self : ...
7395 def __init__ (
7496 self ,
7597 spec : list [str ] | object | type [object ] | None = ...,
@@ -156,6 +178,8 @@ class _patch(Generic[_T]):
156178 autospec : Any | None ,
157179 new_callable : Any | None ,
158180 kwargs : Mapping [str , Any ],
181+ * ,
182+ unsafe : bool = ...,
159183 ) -> None : ...
160184 def copy (self ) -> _patch [_T ]: ...
161185 def __call__ (self , func : Callable [..., _R ]) -> Callable [..., _R ]: ...
@@ -182,6 +206,8 @@ class _patch_dict:
182206 clear : Any
183207 def __init__ (self , in_dict : Any , values : Any = ..., clear : Any = ..., ** kwargs : Any ) -> None : ...
184208 def __call__ (self , f : Any ) -> Any : ...
209+ def decorate_callable (self , f : _F ) -> _F : ...
210+ def decorate_async_callable (self , f : _AF ) -> _AF : ...
185211 def decorate_class (self , klass : Any ) -> Any : ...
186212 def __enter__ (self ) -> Any : ...
187213 def __exit__ (self , * args : object ) -> Any : ...
@@ -201,6 +227,7 @@ class _patcher:
201227 spec_set : Any | None = ...,
202228 autospec : Any | None = ...,
203229 new_callable : Any | None = ...,
230+ unsafe : bool = ...,
204231 ** kwargs : Any ,
205232 ) -> _patch [MagicMock | AsyncMock ]: ...
206233 # This overload also covers the case, where new==DEFAULT. In this case, the return type is _patch[Any].
@@ -216,6 +243,8 @@ class _patcher:
216243 spec_set : Any | None = ...,
217244 autospec : Any | None = ...,
218245 new_callable : Any | None = ...,
246+ * ,
247+ unsafe : bool = ...,
219248 ** kwargs : Any ,
220249 ) -> _patch [_T ]: ...
221250 @overload
@@ -229,6 +258,7 @@ class _patcher:
229258 spec_set : Any | None = ...,
230259 autospec : Any | None = ...,
231260 new_callable : Any | None = ...,
261+ unsafe : bool = ...,
232262 ** kwargs : Any ,
233263 ) -> _patch [MagicMock | AsyncMock ]: ...
234264 @overload
@@ -242,6 +272,8 @@ class _patcher:
242272 spec_set : Any | None = ...,
243273 autospec : Any | None = ...,
244274 new_callable : Any | None = ...,
275+ * ,
276+ unsafe : bool = ...,
245277 ** kwargs : Any ,
246278 ) -> _patch [_T ]: ...
247279 def multiple (
@@ -252,6 +284,8 @@ class _patcher:
252284 spec_set : Any | None = ...,
253285 autospec : Any | None = ...,
254286 new_callable : Any | None = ...,
287+ * ,
288+ unsafe : bool = ...,
255289 ** kwargs : _T ,
256290 ) -> _patch [_T ]: ...
257291 def stopall (self ) -> None : ...
@@ -269,21 +303,23 @@ class MagicMock(MagicMixin, Mock):
269303
270304class AsyncMockMixin (Base ):
271305 def __init__ (self , * args : Any , ** kwargs : Any ) -> None : ...
272- def assert_awaited (self ) -> None : ...
273- def assert_awaited_once (self ) -> None : ...
274- def assert_awaited_with (self , * args : Any , ** kwargs : Any ) -> None : ...
275- def assert_awaited_once_with (self , * args : Any , ** kwargs : Any ) -> None : ...
276- def assert_any_await (self , * args : Any , ** kwargs : Any ) -> None : ...
277- def assert_has_awaits (self , calls : _CallList , any_order : bool = ...) -> None : ...
278- def assert_not_awaited (self ) -> None : ...
306+ def assert_awaited (_mock_self ) -> None : ...
307+ def assert_awaited_once (_mock_self ) -> None : ...
308+ def assert_awaited_with (_mock_self , * args : Any , ** kwargs : Any ) -> None : ...
309+ def assert_awaited_once_with (_mock_self , * args : Any , ** kwargs : Any ) -> None : ...
310+ def assert_any_await (_mock_self , * args : Any , ** kwargs : Any ) -> None : ...
311+ def assert_has_awaits (_mock_self , calls : _CallList , any_order : bool = ...) -> None : ...
312+ def assert_not_awaited (_mock_self ) -> None : ...
279313 def reset_mock (self , * args : Any , ** kwargs : Any ) -> None : ...
280314 await_count : int
281315 await_args : _Call | None
282316 await_args_list : _CallList
317+ __name__ : str
318+ __defaults__ : tuple [Any , ...]
319+ __kwdefaults__ : dict [str , Any ]
320+ __annotations__ : dict [str , Any ] | None # type: ignore[assignment]
283321
284- class AsyncMagicMixin (MagicMixin ):
285- def __init__ (self , * args : Any , ** kw : Any ) -> None : ...
286-
322+ class AsyncMagicMixin (MagicMixin ): ...
287323class AsyncMock (AsyncMockMixin , AsyncMagicMixin , Mock ): ...
288324
289325class MagicProxy (Base ):
@@ -300,7 +336,14 @@ class _ANY:
300336ANY : Any
301337
302338def create_autospec (
303- spec : Any , spec_set : Any = ..., instance : Any = ..., _parent : Any | None = ..., _name : Any | None = ..., ** kwargs : Any
339+ spec : Any ,
340+ spec_set : Any = ...,
341+ instance : Any = ...,
342+ _parent : Any | None = ...,
343+ _name : Any | None = ...,
344+ * ,
345+ unsafe : bool = ...,
346+ ** kwargs : Any ,
304347) -> Any : ...
305348
306349class _SpecState :
0 commit comments