From eb88fee745c6a84315196ee1c946dc566bf4b7bd Mon Sep 17 00:00:00 2001 From: Zixuan James Li Date: Mon, 15 Aug 2022 15:50:30 -0400 Subject: [PATCH] rest: Remove kwargs from rest_path. The only caller that passes the kwargs argument is the avatar rest_path. The application of kwargs can be rewritten with a wrapper. Signed-off-by: Zixuan James Li --- zerver/lib/rest.py | 5 ++--- zerver/views/users.py | 6 ++++++ zproject/urls.py | 7 +++++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/zerver/lib/rest.py b/zerver/lib/rest.py index be9f25806c..14db988222 100644 --- a/zerver/lib/rest.py +++ b/zerver/lib/rest.py @@ -1,5 +1,5 @@ from functools import wraps -from typing import Any, Callable, Dict, Mapping, Set, Tuple, Union, cast +from typing import Any, Callable, Dict, Set, Tuple, Union, cast from django.http import HttpRequest, HttpResponse from django.urls import path @@ -199,7 +199,6 @@ def rest_dispatch(request: HttpRequest, **kwargs: Any) -> HttpResponse: def rest_path( route: str, - kwargs: Mapping[str, object] = {}, **handlers: Union[Callable[..., HttpResponse], Tuple[Callable[..., HttpResponse], Set[str]]], ) -> URLPattern: - return path(route, rest_dispatch, {**kwargs, **handlers}) + return path(route, rest_dispatch, handlers) diff --git a/zerver/views/users.py b/zerver/views/users.py index 4d07b49173..178743bcb8 100644 --- a/zerver/views/users.py +++ b/zerver/views/users.py @@ -324,6 +324,12 @@ def avatar( return redirect(url) +def avatar_medium( + request: HttpRequest, maybe_user_profile: Union[UserProfile, AnonymousUser], email_or_id: str +) -> HttpResponse: + return avatar(request, maybe_user_profile, email_or_id, medium=True) + + def get_stream_name(stream: Optional[Stream]) -> Optional[str]: if stream: return stream.name diff --git a/zproject/urls.py b/zproject/urls.py index 9959eca7cb..7afc9c52bd 100644 --- a/zproject/urls.py +++ b/zproject/urls.py @@ -195,6 +195,7 @@ from zerver.views.user_settings import ( from zerver.views.users import ( add_bot_backend, avatar, + avatar_medium, create_user_backend, deactivate_bot_backend, deactivate_user_backend, @@ -725,8 +726,10 @@ urls += [ ), rest_path( "avatar//medium", - {"medium": True}, - GET=(avatar, {"override_api_url_scheme", "allow_anonymous_user_web"}), + GET=( + avatar_medium, + {"override_api_url_scheme", "allow_anonymous_user_web"}, + ), ), ]