Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
typing: Remove FuncT.
Zixuan James Li30536caa68f0
diff --git a/zerver/openapi/python_examples.py b/zerver/openapi/python_examples.pyindex de52ca96882..90ab39f53cb 100644--- a/zerver/openapi/python_examples.py+++ b/zerver/openapi/python_examples.py@@ -17,8 +17,9 @@ import osimport sysfrom email.headerregistry import Addressfrom functools import wraps-from typing import Any, Callable, Dict, List, Set, TypeVar, cast+from typing import Any, Callable, Dict, List, Set, TypeVar+from typing_extensions import ParamSpecfrom zulip import Clientfrom zerver.models import get_realm, get_user@@ -30,10 +31,13 @@ TEST_FUNCTIONS: Dict[str, Callable[..., object]] = {}REGISTERED_TEST_FUNCTIONS: Set[str] = set()CALLED_TEST_FUNCTIONS: Set[str] = set()-FuncT = TypeVar("FuncT", bound=Callable[..., object])+ParamT = ParamSpec("ParamT")+ReturnT = TypeVar("ReturnT")-def openapi_test_function(endpoint: str) -> Callable[[FuncT], FuncT]:+def openapi_test_function(+ endpoint: str,+) -> Callable[[Callable[ParamT, ReturnT]], Callable[ParamT, ReturnT]]:"""This decorator is used to register an OpenAPI test function withits endpoint. Example usage:@@ -41,16 +45,16 @@ def openapi_test_function(endpoint: str) -> Callable[[FuncT], FuncT]:def ..."""- def wrapper(test_func: FuncT) -> FuncT:+ def wrapper(test_func: Callable[ParamT, ReturnT]) -> Callable[ParamT, ReturnT]:@wraps(test_func)- def _record_calls_wrapper(*args: object, **kwargs: object) -> object:+ def _record_calls_wrapper(*args: ParamT.args, **kwargs: ParamT.kwargs) -> ReturnT:CALLED_TEST_FUNCTIONS.add(test_func.__name__)return test_func(*args, **kwargs)REGISTERED_TEST_FUNCTIONS.add(test_func.__name__)TEST_FUNCTIONS[endpoint] = _record_calls_wrapper- return cast(FuncT, _record_calls_wrapper) # https://github.com/python/mypy/issues/1927+ return _record_calls_wrapperreturn wrapperdiff --git a/zerver/tests/test_service_bot_system.py b/zerver/tests/test_service_bot_system.pyindex fc7557d9e1c..04021eae2bd 100644--- a/zerver/tests/test_service_bot_system.py+++ b/zerver/tests/test_service_bot_system.py@@ -1,10 +1,11 @@from functools import wraps-from typing import Any, Callable, Dict, Optional, TypeVar, cast+from typing import Any, Callable, Dict, Optionalfrom unittest import mockimport orjsonfrom django.conf import settingsfrom django.test import override_settings+from typing_extensions import Concatenate, ParamSpecfrom zerver.actions.create_user import do_create_userfrom zerver.actions.message_send import get_service_bot_events@@ -413,20 +414,22 @@ class TestServiceBotConfigHandler(ZulipTestCase):self.bot_handler.send_message(message={"type": "private", "to": []})-FuncT = TypeVar("FuncT", bound=Callable[..., None])+ParamT = ParamSpec("ParamT")-def for_all_bot_types(test_func: FuncT) -> FuncT:+def for_all_bot_types(+ test_func: Callable[Concatenate["TestServiceBotEventTriggers", ParamT], None]+) -> Callable[Concatenate["TestServiceBotEventTriggers", ParamT], None]:@wraps(test_func)- def _wrapped(*args: object, **kwargs: object) -> None:- assert len(args) > 0- self = cast(TestServiceBotEventTriggers, args[0])+ def _wrapped(+ self: "TestServiceBotEventTriggers", /, *args: ParamT.args, **kwargs: ParamT.kwargs+ ) -> None:for bot_type in BOT_TYPE_TO_QUEUE_NAME:self.bot_profile.bot_type = bot_typeself.bot_profile.save()- test_func(*args, **kwargs)+ test_func(self, *args, **kwargs)- return cast(FuncT, _wrapped) # https://github.com/python/mypy/issues/1927+ return _wrappedclass TestServiceBotEventTriggers(ZulipTestCase):