From 88c4ea7ac6e58051631a352667ec91ca845903bd Mon Sep 17 00:00:00 2001 From: Viicos <65306057+Viicos@users.noreply.github.com> Date: Mon, 22 Jan 2024 15:43:59 +0100 Subject: [PATCH] Improve type definition of `Mocker.__call__` --- requests_mock/mocker.pyi | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/requests_mock/mocker.pyi b/requests_mock/mocker.pyi index ea68205..6b3eae5 100644 --- a/requests_mock/mocker.pyi +++ b/requests_mock/mocker.pyi @@ -3,7 +3,7 @@ from json import JSONEncoder from http.cookiejar import CookieJar from io import IOBase -from typing import Any, Callable, Dict, List, Optional, Pattern, Type, TypeVar, Union +from typing import Any, Callable, Dict, List, Optional, Pattern, Type, TypeVar, Union, overload from requests import Response, Session from urllib3.response import HTTPResponse @@ -239,6 +239,7 @@ class MockerCore: ) -> _Matcher: ... _T = TypeVar('_T') +_CallableT = TypeVar("_CallableT", bound=Callable) class Mocker(MockerCore): TEST_PREFIX: str = ... @@ -255,9 +256,12 @@ class Mocker(MockerCore): ) -> None: ... def __enter__(self) -> Any: ... def __exit__(self, type: Any, value: Any, traceback: Any) -> None: ... - def __call__(self, obj: Any) -> Any: ... + @overload + def __call__(self, obj: type[_T]) -> type[_T]: ... + @overload + def __call__(self, obj: _CallableT) -> _CallableT: ... def copy(self) -> Mocker: ... - def decorate_callable(self, func: Callable[..., _T]) -> Callable[..., _T]: ... + def decorate_callable(self, func: _CallableT) -> _CallableT: ... def decorate_class(self, klass: Type[_T]) -> Type[_T]: ... mock = Mocker