Skip to content
Open
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
9 changes: 8 additions & 1 deletion stdlib/unittest/mock.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,14 @@ class _patch_dict:
values: Any
clear: Any
def __init__(self, in_dict: Any, values: Any = (), clear: Any = False, **kwargs: Any) -> None: ...
def __call__(self, f: Any) -> Any: ...

@overload
def __call__(self, f: _TT) -> _TT: ...
@overload
def __call__(self, f: _AF) -> _AF: ...
@overload
def __call__(self, f: _F) -> _F: ...
Comment on lines +305 to +310

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not totally clear to me how having three overloads here is any different to doing this:

Suggested change
@overload
def __call__(self, f: _TT) -> _TT: ...
@overload
def __call__(self, f: _AF) -> _AF: ...
@overload
def __call__(self, f: _F) -> _F: ...
def __call__(self, f: _F) -> _F: ...

Any type assignable to type[Any] (upper bound of _TT) or Callable[..., Coroutine[Any, Any, Any]](upper bound of _AF) will also be assignable to Callable[..., Any] (upper bound of _F), and a type checker will always pick the most precise type when solving a generic call


def __enter__(self) -> Any: ...
def __exit__(self, *args: object) -> Any: ...
def decorate_callable(self, f: _F) -> _F: ...
Expand Down