-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Add missing typings to unittest.mock
#7431
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
JelleZijlstra
merged 8 commits into
python:master
from
itaisteinherz:feature/unittest-mock-strict
Mar 6, 2022
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8866ad0
Add missing typings to `unittest.mock`
itaisteinherz 8392dbc
Strictly typecheck `unittest.mock` with pyright
itaisteinherz 6be90f8
Overhaul `_Call.__new__` typings and add missing typings
itaisteinherz 1f474b5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 20ec6fa
Make `_Call` non-generic
itaisteinherz 03bafaa
Fix linting
itaisteinherz b66978e
CR improvement
itaisteinherz d1cbadb
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import sys | ||
from _typeshed import Self | ||
from contextlib import _GeneratorContextManager | ||
from typing import Any, Awaitable, Callable, Generic, Iterable, Mapping, Sequence, TypeVar, overload | ||
from typing_extensions import Literal | ||
|
||
|
@@ -75,11 +76,15 @@ class _Sentinel: | |
sentinel: Any | ||
DEFAULT: Any | ||
|
||
_ArgsKwargs = tuple[tuple[Any, ...], Mapping[str, Any]] | ||
_NameArgsKwargs = tuple[str, tuple[Any, ...], Mapping[str, Any]] | ||
_CallValue = str | tuple[Any, ...] | Mapping[str, Any] | _ArgsKwargs | _NameArgsKwargs | ||
|
||
class _Call(tuple[Any, ...]): | ||
def __new__( | ||
cls: type[Self], | ||
value: Any = ..., | ||
name: Any | None = ..., | ||
value: _CallValue = ..., | ||
name: str | None = ..., | ||
parent: Any | None = ..., | ||
two: bool = ..., | ||
from_kall: bool = ..., | ||
|
@@ -88,7 +93,7 @@ class _Call(tuple[Any, ...]): | |
parent: Any | ||
from_kall: Any | ||
def __init__( | ||
self, value: Any = ..., name: Any | None = ..., parent: Any | None = ..., two: bool = ..., from_kall: bool = ... | ||
self, value: _CallValue = ..., name: str | None = ..., parent: Any | None = ..., two: bool = ..., from_kall: bool = ... | ||
) -> None: ... | ||
def __eq__(self, other: object) -> bool: ... | ||
def __ne__(self, __other: object) -> bool: ... | ||
|
@@ -97,9 +102,9 @@ class _Call(tuple[Any, ...]): | |
def __getattribute__(self, attr: str) -> Any: ... | ||
if sys.version_info >= (3, 8): | ||
@property | ||
def args(self): ... | ||
def args(self) -> tuple[Any, ...]: ... | ||
@property | ||
def kwargs(self): ... | ||
def kwargs(self) -> Mapping[str, Any]: ... | ||
|
||
def call_list(self) -> Any: ... | ||
|
||
|
@@ -244,7 +249,9 @@ class _patch(Generic[_T]): | |
@overload | ||
def __call__(self, func: Callable[..., _R]) -> Callable[..., _R]: ... | ||
if sys.version_info >= (3, 8): | ||
def decoration_helper(self, patched, args, keywargs): ... | ||
def decoration_helper( | ||
self, patched: _patch[Any], args: Sequence[Any], keywargs: Any | ||
) -> _GeneratorContextManager[tuple[Sequence[Any], Any]]: ... | ||
|
||
def decorate_class(self, klass: _TT) -> _TT: ... | ||
def decorate_callable(self, func: Callable[..., _R]) -> Callable[..., _R]: ... | ||
|
@@ -428,14 +435,14 @@ if sys.version_info >= (3, 8): | |
class AsyncMock(AsyncMockMixin, AsyncMagicMixin, Mock): ... # type: ignore # argument disparities between base classes | ||
|
||
class MagicProxy: | ||
name: Any | ||
name: str | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if I should change this, however it doesn't really make much sense to me that |
||
parent: Any | ||
def __init__(self, name, parent) -> None: ... | ||
def __init__(self, name: str, parent: Any) -> None: ... | ||
if sys.version_info < (3, 8): | ||
def __call__(self, *args: Any, **kwargs: Any) -> Any: ... | ||
|
||
def create_mock(self): ... | ||
def __get__(self, obj, _type: Any | None = ...): ... | ||
def create_mock(self) -> Any: ... | ||
def __get__(self, obj: Any, _type: Any | None = ...) -> Any: ... | ||
|
||
class _ANY: | ||
def __eq__(self, other: object) -> Literal[True]: ... | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that
kwargs
is typed asAny
in the rest of the stubs, but I wanted to be more strict here.