mypy: Centralize ViewFuncT definition into new file zerver/lib/types.py.

Originally was going to centralize this in zerver/lib/request.pyi, but this
file is not visible at run-time, being only a stub. The matching request.py
file seemed inappropriate, as it doesn't actually use ViewFuncT.
This commit is contained in:
neiljp (Neil Pilgrim) 2018-03-13 16:44:46 +00:00 committed by Tim Abbott
parent 95067ddb08
commit 17937175ac
4 changed files with 7 additions and 5 deletions

View File

@ -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")

View File

@ -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): ...

4
zerver/lib/types.py Normal file
View File

@ -0,0 +1,4 @@
from typing import TypeVar, Callable
from django.http import HttpResponse
ViewFuncT = TypeVar('ViewFuncT', bound=Callable[..., HttpResponse])

View File

@ -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