Add overloads to unittest.mock._patch_dict.__call__ - #16310
Conversation
|
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
| @overload | ||
| def __call__(self, f: _TT) -> _TT: ... | ||
| @overload | ||
| def __call__(self, f: _AF) -> _AF: ... | ||
| @overload | ||
| def __call__(self, f: _F) -> _F: ... |
There was a problem hiding this comment.
it's not totally clear to me how having three overloads here is any different to doing this:
| @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
|
I dug through the blame a bit to see if there had been any previous churn or discussion about this signature, since annotations in |
|
This LGTM other than the simplification I suggested above, it does seem like this preserves the wrapped function's signature. Thanks! |
Resolves #16307