Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8365b1a

Browse files
Bump mock to 5.0.* (#9423)
1 parent 554989e commit 8365b1a

3 files changed

Lines changed: 62 additions & 30 deletions

File tree

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,2 @@
1-
mock.NonCallableMock.__new__
21
mock.patch
3-
mock.mock.NonCallableMock.__new__
42
mock.mock.patch
5-
6-
# Methods with a first argument that's not called "self"
7-
mock.mock.AsyncMockMixin.assert_any_await
8-
mock.mock.AsyncMockMixin.assert_awaited
9-
mock.mock.AsyncMockMixin.assert_awaited_once
10-
mock.mock.AsyncMockMixin.assert_awaited_once_with
11-
mock.mock.AsyncMockMixin.assert_awaited_with
12-
mock.mock.AsyncMockMixin.assert_has_awaits
13-
mock.mock.AsyncMockMixin.assert_not_awaited

stubs/mock/METADATA.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version = "4.0.*"
1+
version = "5.0.*"
22

33
[tool.stubtest]
44
ignore_missing_stub = false

stubs/mock/mock/mock.pyi

Lines changed: 61 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
from _typeshed import Self
2-
from collections.abc import Awaitable, Callable, Mapping, Sequence
2+
from collections.abc import Callable, Coroutine, Mapping, Sequence
33
from contextlib import AbstractContextManager
44
from types import TracebackType
55
from typing import Any, Generic, TypeVar, overload
66
from 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

3846
class _Call(tuple[Any, ...]):
3947
def __new__(
@@ -69,7 +77,21 @@ class Base:
6977
def __init__(self, *args: Any, **kwargs: Any) -> None: ...
7078

7179
class 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

270304
class 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): ...
287323
class AsyncMock(AsyncMockMixin, AsyncMagicMixin, Mock): ...
288324

289325
class MagicProxy(Base):
@@ -300,7 +336,14 @@ class _ANY:
300336
ANY: Any
301337

302338
def 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

306349
class _SpecState:

0 commit comments

Comments
 (0)