test_service_bot_system: Strengthen for_all_bot_types decorator type.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2021-02-15 15:00:26 -08:00
committed by Tim Abbott
parent 04a5e0c339
commit dd2a3b45cd

View File

@@ -1,5 +1,5 @@
from functools import wraps
from typing import Any, Callable, Dict, Optional, cast
from typing import Any, Callable, Dict, Optional, TypeVar, cast
from unittest import mock
import orjson
@@ -409,7 +409,10 @@ class TestServiceBotConfigHandler(ZulipTestCase):
self.bot_handler.send_message(message={"type": "private", "to": []})
def for_all_bot_types(test_func: Callable[..., None]) -> Callable[..., None]:
FuncT = TypeVar("FuncT", bound=Callable[..., None])
def for_all_bot_types(test_func: FuncT) -> FuncT:
@wraps(test_func)
def _wrapped(*args: object, **kwargs: object) -> None:
assert len(args) > 0
@@ -419,7 +422,7 @@ def for_all_bot_types(test_func: Callable[..., None]) -> Callable[..., None]:
self.bot_profile.save()
test_func(*args, **kwargs)
return _wrapped
return cast(FuncT, _wrapped) # https://github.com/python/mypy/issues/1927
class TestServiceBotEventTriggers(ZulipTestCase):