diff --git a/zerver/decorator.py b/zerver/decorator.py index 5ea6b9bdee..3a84a416b9 100644 --- a/zerver/decorator.py +++ b/zerver/decorator.py @@ -16,6 +16,7 @@ from zerver.lib.subdomains import get_subdomain, user_matches_subdomain from zerver.lib.timestamp import datetime_to_timestamp, timestamp_to_datetime from zerver.lib.utils import statsd, is_remote_server from zerver.lib.exceptions import RateLimited, JsonableError, ErrorCode +from zerver.lib.types import ViewFuncT from zerver.lib.rate_limiter import incr_ratelimit, is_ratelimited, \ api_calls_left, RateLimitedUser @@ -42,7 +43,6 @@ else: get_remote_server_by_uuid = Mock() RemoteZulipServer = Mock() # type: ignore # https://github.com/JukkaL/mypy/issues/1188 -ViewFuncT = TypeVar('ViewFuncT', bound=Callable[..., HttpResponse]) ReturnT = TypeVar('ReturnT') webhook_logger = logging.getLogger("zulip.zerver.webhooks") diff --git a/zerver/lib/request.pyi b/zerver/lib/request.pyi index bc308dce7f..3497a68d96 100644 --- a/zerver/lib/request.pyi +++ b/zerver/lib/request.pyi @@ -7,14 +7,13 @@ # types. from typing import Any, Callable, Text, TypeVar, Optional, Union, Type -from django.http import HttpResponse +from zerver.lib.types import ViewFuncT from zerver.lib.exceptions import JsonableError as JsonableError Validator = Callable[[str, Any], Optional[str]] ResultT = TypeVar('ResultT') -ViewFuncT = TypeVar('ViewFuncT', bound=Callable[..., HttpResponse]) class RequestVariableMissingError(JsonableError): ... class RequestVariableConversionError(JsonableError): ... diff --git a/zerver/lib/types.py b/zerver/lib/types.py new file mode 100644 index 0000000000..ad1b08724b --- /dev/null +++ b/zerver/lib/types.py @@ -0,0 +1,4 @@ +from typing import TypeVar, Callable +from django.http import HttpResponse + +ViewFuncT = TypeVar('ViewFuncT', bound=Callable[..., HttpResponse]) diff --git a/zerver/webhooks/beanstalk/view.py b/zerver/webhooks/beanstalk/view.py index 15c8d22a67..540c1fa28b 100644 --- a/zerver/webhooks/beanstalk/view.py +++ b/zerver/webhooks/beanstalk/view.py @@ -8,14 +8,13 @@ from django.http import HttpRequest, HttpResponse from zerver.decorator import authenticated_rest_api_view from zerver.lib.actions import check_send_stream_message +from zerver.lib.types import ViewFuncT from zerver.lib.request import REQ, has_request_variables from zerver.lib.response import json_success from zerver.lib.validator import check_dict from zerver.models import UserProfile, get_client from zerver.webhooks.github.view import build_message_from_gitlog -ViewFuncT = TypeVar('ViewFuncT', bound=Callable[..., HttpResponse]) - # Beanstalk's web hook UI rejects url with a @ in the username section of a url # So we ask the user to replace them with %40 # We manually fix the username here before passing it along to @authenticated_rest_api_view