request: Replace type argument hack with a different workaround.

This works in mypy 0.770 and is needed for mypy 0.780.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2020-06-05 18:15:23 -07:00 committed by Tim Abbott
parent fb6047c4ae
commit 22178c169e
2 changed files with 10 additions and 18 deletions

View File

@ -11,7 +11,7 @@ from zerver.lib.types import Validator, ViewFuncT
from django.http import HttpRequest, HttpResponse from django.http import HttpRequest, HttpResponse
from typing import Any, Callable, Dict, Generic, List, Optional, Type, TypeVar, Union, cast, overload from typing import Any, Callable, Dict, Generic, List, Optional, TypeVar, Union, cast, overload
from typing_extensions import Literal from typing_extensions import Literal
class RequestConfusingParmsError(JsonableError): class RequestConfusingParmsError(JsonableError):
@ -64,7 +64,6 @@ class _REQ(Generic[ResultT]):
self, self,
whence: Optional[str] = None, whence: Optional[str] = None,
*, *,
type: Type[ResultT] = Type[None],
converter: Optional[Callable[[str], ResultT]] = None, converter: Optional[Callable[[str], ResultT]] = None,
default: Union[_NotSpecified, ResultT, None] = NotSpecified, default: Union[_NotSpecified, ResultT, None] = NotSpecified,
validator: Optional[Validator] = None, validator: Optional[Validator] = None,
@ -95,10 +94,6 @@ class _REQ(Generic[ResultT]):
argument_type: pass 'body' to extract the parsed JSON argument_type: pass 'body' to extract the parsed JSON
corresponding to the request body corresponding to the request body
type: a hint to typing (using mypy) what the type of this parameter is.
Currently only typically necessary if default=None and the type cannot
be inferred in another way (eg. via converter).
aliases: alternate names for the POST var aliases: alternate names for the POST var
path_only: Used for parameters included in the URL that we still want path_only: Used for parameters included in the URL that we still want
@ -137,7 +132,6 @@ class _REQ(Generic[ResultT]):
def REQ( def REQ(
whence: Optional[str] = ..., whence: Optional[str] = ...,
*, *,
type: Type[ResultT] = ...,
converter: Callable[[str], ResultT], converter: Callable[[str], ResultT],
default: ResultT = ..., default: ResultT = ...,
intentionally_undocumented: bool = ..., intentionally_undocumented: bool = ...,
@ -152,7 +146,6 @@ def REQ(
def REQ( def REQ(
whence: Optional[str] = ..., whence: Optional[str] = ...,
*, *,
type: Type[ResultT] = ...,
default: ResultT = ..., default: ResultT = ...,
validator: Validator, validator: Validator,
intentionally_undocumented: bool = ..., intentionally_undocumented: bool = ...,
@ -167,7 +160,6 @@ def REQ(
def REQ( def REQ(
whence: Optional[str] = ..., whence: Optional[str] = ...,
*, *,
type: Type[str] = ...,
default: str = ..., default: str = ...,
str_validator: Optional[Validator] = ..., str_validator: Optional[Validator] = ...,
intentionally_undocumented: bool = ..., intentionally_undocumented: bool = ...,
@ -182,7 +174,6 @@ def REQ(
def REQ( def REQ(
whence: Optional[str] = ..., whence: Optional[str] = ...,
*, *,
type: Type[str] = ...,
default: None, default: None,
str_validator: Optional[Validator] = ..., str_validator: Optional[Validator] = ...,
intentionally_undocumented: bool = ..., intentionally_undocumented: bool = ...,
@ -197,7 +188,6 @@ def REQ(
def REQ( def REQ(
whence: Optional[str] = ..., whence: Optional[str] = ...,
*, *,
type: Type[ResultT] = ...,
default: ResultT = ..., default: ResultT = ...,
str_validator: Optional[Validator] = ..., str_validator: Optional[Validator] = ...,
argument_type: Literal["body"], argument_type: Literal["body"],
@ -212,7 +202,6 @@ def REQ(
def REQ( def REQ(
whence: Optional[str] = None, whence: Optional[str] = None,
*, *,
type: Type[ResultT] = Type[None],
converter: Optional[Callable[[str], ResultT]] = None, converter: Optional[Callable[[str], ResultT]] = None,
default: Union[_REQ._NotSpecified, ResultT] = _REQ.NotSpecified, default: Union[_REQ._NotSpecified, ResultT] = _REQ.NotSpecified,
validator: Optional[Validator] = None, validator: Optional[Validator] = None,
@ -225,7 +214,6 @@ def REQ(
) -> ResultT: ) -> ResultT:
return cast(ResultT, _REQ( return cast(ResultT, _REQ(
whence, whence,
type=type,
converter=converter, converter=converter,
default=default, default=default,
validator=validator, validator=validator,

View File

@ -7,12 +7,16 @@ from zerver.lib.actions import check_send_typing_notification, \
from zerver.lib.response import json_success from zerver.lib.response import json_success
from zerver.models import UserProfile from zerver.models import UserProfile
EMPTY_STRS: List[str] = []
EMPTY_STRS_OR_INTS: Union[List[str], List[int]] = EMPTY_STRS
@has_request_variables @has_request_variables
def send_notification_backend( def send_notification_backend(
request: HttpRequest, user_profile: UserProfile, request: HttpRequest, user_profile: UserProfile,
operator: str=REQ('op'), operator: str=REQ('op'),
notification_to: Union[List[str], List[int]]=REQ( notification_to: Union[List[str], List[int]]=REQ(
'to', type=Union[List[str], List[int]], 'to', converter=extract_private_recipients, default=EMPTY_STRS_OR_INTS,
converter=extract_private_recipients, default=[])) -> HttpResponse: ),
) -> HttpResponse:
check_send_typing_notification(user_profile, notification_to, operator) check_send_typing_notification(user_profile, notification_to, operator)
return json_success() return json_success()