Skip to content

Make AsyncMock stubs available for python 3.6+ #5948

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions stubs/mock/METADATA.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
version = "0.1"
python2 = true
version = "4.0"
283 changes: 101 additions & 182 deletions stubs/mock/mock.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -164,63 +164,35 @@ class _patch(Generic[_T]):
autospec: Any
kwargs: Mapping[str, Any]
additional_patchers: Any
if sys.version_info >= (3, 8):
@overload
def __init__(
self: _patch[MagicMock | AsyncMock],
getter: Callable[[], Any],
attribute: str,
*,
spec: Any | None,
create: bool,
spec_set: Any | None,
autospec: Any | None,
new_callable: Any | None,
kwargs: Mapping[str, Any],
) -> None: ...
# This overload also covers the case, where new==DEFAULT. In this case, self is _patch[Any].
# Ideally we'd be able to add an overload for it so that self is _patch[MagicMock],
# but that's impossible with the current type system.
@overload
def __init__(
self: _patch[_T],
getter: Callable[[], Any],
attribute: str,
new: _T,
spec: Any | None,
create: bool,
spec_set: Any | None,
autospec: Any | None,
new_callable: Any | None,
kwargs: Mapping[str, Any],
) -> None: ...
else:
@overload
def __init__(
self: _patch[MagicMock],
getter: Callable[[], Any],
attribute: str,
*,
spec: Any | None,
create: bool,
spec_set: Any | None,
autospec: Any | None,
new_callable: Any | None,
kwargs: Mapping[str, Any],
) -> None: ...
@overload
def __init__(
self: _patch[_T],
getter: Callable[[], Any],
attribute: str,
new: _T,
spec: Any | None,
create: bool,
spec_set: Any | None,
autospec: Any | None,
new_callable: Any | None,
kwargs: Mapping[str, Any],
) -> None: ...
@overload
def __init__(
self: _patch[MagicMock | AsyncMock],
getter: Callable[[], Any],
attribute: str,
*,
spec: Any | None,
create: bool,
spec_set: Any | None,
autospec: Any | None,
new_callable: Any | None,
kwargs: Mapping[str, Any],
) -> None: ...
# This overload also covers the case, where new==DEFAULT. In this case, self is _patch[Any].
# Ideally we'd be able to add an overload for it so that self is _patch[MagicMock],
# but that's impossible with the current type system.
@overload
def __init__(
self: _patch[_T],
getter: Callable[[], Any],
attribute: str,
new: _T,
spec: Any | None,
create: bool,
spec_set: Any | None,
autospec: Any | None,
new_callable: Any | None,
kwargs: Mapping[str, Any],
) -> None: ...
def copy(self) -> _patch[_T]: ...
def __call__(self, func: Callable[..., _R]) -> Callable[..., _R]: ...
def decorate_class(self, klass: _TT) -> _TT: ...
Expand Down Expand Up @@ -249,113 +221,59 @@ class _patch_dict:
class _patcher:
TEST_PREFIX: str
dict: Type[_patch_dict]
if sys.version_info >= (3, 8):
@overload
def __call__( # type: ignore
self,
target: Any,
*,
spec: Any | None = ...,
create: bool = ...,
spec_set: Any | None = ...,
autospec: Any | None = ...,
new_callable: Any | None = ...,
**kwargs: Any,
) -> _patch[MagicMock | AsyncMock]: ...
# This overload also covers the case, where new==DEFAULT. In this case, the return type is _patch[Any].
# Ideally we'd be able to add an overload for it so that the return type is _patch[MagicMock],
# but that's impossible with the current type system.
@overload
def __call__(
self,
target: Any,
new: _T,
spec: Any | None = ...,
create: bool = ...,
spec_set: Any | None = ...,
autospec: Any | None = ...,
new_callable: Any | None = ...,
**kwargs: Any,
) -> _patch[_T]: ...
else:
@overload
def __call__( # type: ignore
self,
target: Any,
*,
spec: Any | None = ...,
create: bool = ...,
spec_set: Any | None = ...,
autospec: Any | None = ...,
new_callable: Any | None = ...,
**kwargs: Any,
) -> _patch[MagicMock]: ...
@overload
def __call__(
self,
target: Any,
new: _T,
spec: Any | None = ...,
create: bool = ...,
spec_set: Any | None = ...,
autospec: Any | None = ...,
new_callable: Any | None = ...,
**kwargs: Any,
) -> _patch[_T]: ...
if sys.version_info >= (3, 8):
@overload
def object( # type: ignore
self,
target: Any,
attribute: Text,
*,
spec: Any | None = ...,
create: bool = ...,
spec_set: Any | None = ...,
autospec: Any | None = ...,
new_callable: Any | None = ...,
**kwargs: Any,
) -> _patch[MagicMock | AsyncMock]: ...
@overload
def object(
self,
target: Any,
attribute: Text,
new: _T = ...,
spec: Any | None = ...,
create: bool = ...,
spec_set: Any | None = ...,
autospec: Any | None = ...,
new_callable: Any | None = ...,
**kwargs: Any,
) -> _patch[_T]: ...
else:
@overload
def object( # type: ignore
self,
target: Any,
attribute: Text,
*,
spec: Any | None = ...,
create: bool = ...,
spec_set: Any | None = ...,
autospec: Any | None = ...,
new_callable: Any | None = ...,
**kwargs: Any,
) -> _patch[MagicMock]: ...
@overload
def object(
self,
target: Any,
attribute: Text,
new: _T = ...,
spec: Any | None = ...,
create: bool = ...,
spec_set: Any | None = ...,
autospec: Any | None = ...,
new_callable: Any | None = ...,
**kwargs: Any,
) -> _patch[_T]: ...
@overload
def __call__( # type: ignore
self,
target: Any,
*,
spec: Any | None = ...,
create: bool = ...,
spec_set: Any | None = ...,
autospec: Any | None = ...,
new_callable: Any | None = ...,
**kwargs: Any,
) -> _patch[MagicMock | AsyncMock]: ...
# This overload also covers the case, where new==DEFAULT. In this case, the return type is _patch[Any].
# Ideally we'd be able to add an overload for it so that the return type is _patch[MagicMock],
# but that's impossible with the current type system.
@overload
def __call__(
self,
target: Any,
new: _T,
spec: Any | None = ...,
create: bool = ...,
spec_set: Any | None = ...,
autospec: Any | None = ...,
new_callable: Any | None = ...,
**kwargs: Any,
) -> _patch[_T]: ...
@overload
def object( # type: ignore
self,
target: Any,
attribute: Text,
*,
spec: Any | None = ...,
create: bool = ...,
spec_set: Any | None = ...,
autospec: Any | None = ...,
new_callable: Any | None = ...,
**kwargs: Any,
) -> _patch[MagicMock | AsyncMock]: ...
@overload
def object(
self,
target: Any,
attribute: Text,
new: _T = ...,
spec: Any | None = ...,
create: bool = ...,
spec_set: Any | None = ...,
autospec: Any | None = ...,
new_callable: Any | None = ...,
**kwargs: Any,
) -> _patch[_T]: ...
def multiple(
self,
target: Any,
Expand All @@ -379,24 +297,25 @@ class NonCallableMagicMock(MagicMixin, NonCallableMock):
class MagicMock(MagicMixin, Mock):
def mock_add_spec(self, spec: Any, spec_set: bool = ...) -> None: ...

if sys.version_info >= (3, 8):
class AsyncMockMixin(Base):
def __init__(self, *args: Any, **kwargs: Any) -> None: ...
async def _execute_mock_call(self, *args: Any, **kwargs: Any) -> Any: ...
def assert_awaited(self) -> None: ...
def assert_awaited_once(self) -> None: ...
def assert_awaited_with(self, *args: Any, **kwargs: Any) -> None: ...
def assert_awaited_once_with(self, *args: Any, **kwargs: Any) -> None: ...
def assert_any_await(self, *args: Any, **kwargs: Any) -> None: ...
def assert_has_awaits(self, calls: _CallList, any_order: bool = ...) -> None: ...
def assert_not_awaited(self) -> None: ...
def reset_mock(self, *args: Any, **kwargs: Any) -> None: ...
await_count: int
await_args: _Call | None
await_args_list: _CallList
class AsyncMagicMixin(MagicMixin):
def __init__(self, *args: Any, **kw: Any) -> None: ...
class AsyncMock(AsyncMockMixin, AsyncMagicMixin, Mock): ...
class AsyncMockMixin(Base):
def __init__(self, *args: Any, **kwargs: Any) -> None: ...
async def _execute_mock_call(self, *args: Any, **kwargs: Any) -> Any: ...
def assert_awaited(self) -> None: ...
def assert_awaited_once(self) -> None: ...
def assert_awaited_with(self, *args: Any, **kwargs: Any) -> None: ...
def assert_awaited_once_with(self, *args: Any, **kwargs: Any) -> None: ...
def assert_any_await(self, *args: Any, **kwargs: Any) -> None: ...
def assert_has_awaits(self, calls: _CallList, any_order: bool = ...) -> None: ...
def assert_not_awaited(self) -> None: ...
def reset_mock(self, *args: Any, **kwargs: Any) -> None: ...
await_count: int
await_args: _Call | None
await_args_list: _CallList

class AsyncMagicMixin(MagicMixin):
def __init__(self, *args: Any, **kw: Any) -> None: ...

class AsyncMock(AsyncMockMixin, AsyncMagicMixin, Mock): ...

class MagicProxy:
name: Any
Expand Down