mirror of
				https://github.com/zulip/zulip.git
				synced 2025-10-31 03:53:50 +00:00 
			
		
		
		
	typing: Fix function signatures.
This fixes mypy errors for function signatures discovered with django-stubs.
This commit is contained in:
		| @@ -1,12 +1,12 @@ | ||||
| import re | ||||
| from typing import Any, Dict | ||||
| from typing import Any, Dict, Optional | ||||
|  | ||||
| from django.http import HttpRequest | ||||
| from django.views.debug import SafeExceptionReporterFilter | ||||
|  | ||||
|  | ||||
| class ZulipExceptionReporterFilter(SafeExceptionReporterFilter): | ||||
|     def get_post_parameters(self, request: HttpRequest) -> Dict[str, Any]: | ||||
|     def get_post_parameters(self, request: Optional[HttpRequest]) -> Dict[str, Any]: | ||||
|         post_data = SafeExceptionReporterFilter.get_post_parameters(self, request) | ||||
|         assert isinstance(post_data, dict) | ||||
|         filtered_post = post_data.copy() | ||||
|   | ||||
| @@ -2924,7 +2924,7 @@ def check_update_message( | ||||
|     message_id: int, | ||||
|     stream_id: Optional[int] = None, | ||||
|     topic_name: Optional[str] = None, | ||||
|     propagate_mode: Optional[str] = "change_one", | ||||
|     propagate_mode: str = "change_one", | ||||
|     send_notification_to_old_thread: bool = True, | ||||
|     send_notification_to_new_thread: bool = True, | ||||
|     content: Optional[str] = None, | ||||
|   | ||||
| @@ -2,7 +2,7 @@ import datetime | ||||
| import itertools | ||||
| import time | ||||
| from collections import defaultdict | ||||
| from typing import Any, Dict, List, Set | ||||
| from typing import Any, Dict, Mapping, Sequence, Set | ||||
|  | ||||
| from django.utils.timezone import now as timezone_now | ||||
|  | ||||
| @@ -11,7 +11,7 @@ from zerver.models import PushDeviceToken, Realm, UserPresence, UserProfile, que | ||||
|  | ||||
|  | ||||
| def get_status_dicts_for_rows( | ||||
|     all_rows: List[Dict[str, Any]], mobile_user_ids: Set[int], slim_presence: bool | ||||
|     all_rows: Sequence[Mapping[str, Any]], mobile_user_ids: Set[int], slim_presence: bool | ||||
| ) -> Dict[str, Dict[str, Any]]: | ||||
|  | ||||
|     # Note that datetime values have sub-second granularity, which is | ||||
| @@ -46,7 +46,7 @@ def get_status_dicts_for_rows( | ||||
|  | ||||
|  | ||||
| def get_modern_user_info( | ||||
|     presence_rows: List[Dict[str, Any]], mobile_user_ids: Set[int] | ||||
|     presence_rows: Sequence[Mapping[str, Any]], mobile_user_ids: Set[int] | ||||
| ) -> Dict[str, Any]: | ||||
|  | ||||
|     active_timestamp = None | ||||
| @@ -76,7 +76,7 @@ def get_modern_user_info( | ||||
|  | ||||
|  | ||||
| def get_legacy_user_info( | ||||
|     presence_rows: List[Dict[str, Any]], mobile_user_ids: Set[int] | ||||
|     presence_rows: Sequence[Mapping[str, Any]], mobile_user_ids: Set[int] | ||||
| ) -> Dict[str, Any]: | ||||
|  | ||||
|     # The format of data here is for legacy users of our API, | ||||
|   | ||||
| @@ -297,7 +297,7 @@ class Runner(DiscoverRunner): | ||||
|         self.shallow_tested_templates: Set[str] = set() | ||||
|         template_rendered.connect(self.on_template_rendered) | ||||
|  | ||||
|     def get_resultclass(self) -> Type[TestResult]: | ||||
|     def get_resultclass(self) -> Optional[Type[TextTestResult]]: | ||||
|         return TextTestResult | ||||
|  | ||||
|     def on_template_rendered(self, sender: Any, context: Dict[str, Any], **kwargs: Any) -> None: | ||||
|   | ||||
| @@ -3,6 +3,7 @@ from typing import Dict | ||||
| from unittest.mock import MagicMock, patch | ||||
|  | ||||
| from django.http import HttpRequest | ||||
| from django.http.response import HttpResponse | ||||
|  | ||||
| from zerver.decorator import webhook_view | ||||
| from zerver.lib.actions import do_rename_stream | ||||
| @@ -61,11 +62,11 @@ class WebhooksCommonTestCase(ZulipTestCase): | ||||
|  | ||||
|     def test_notify_bot_owner_on_invalid_json(self) -> None: | ||||
|         @webhook_view("ClientName", notify_bot_owner_on_invalid_json=False) | ||||
|         def my_webhook_no_notify(request: HttpRequest, user_profile: UserProfile) -> None: | ||||
|         def my_webhook_no_notify(request: HttpRequest, user_profile: UserProfile) -> HttpResponse: | ||||
|             raise InvalidJSONError("Malformed JSON") | ||||
|  | ||||
|         @webhook_view("ClientName", notify_bot_owner_on_invalid_json=True) | ||||
|         def my_webhook_notify(request: HttpRequest, user_profile: UserProfile) -> None: | ||||
|         def my_webhook_notify(request: HttpRequest, user_profile: UserProfile) -> HttpResponse: | ||||
|             raise InvalidJSONError("Malformed JSON") | ||||
|  | ||||
|         webhook_bot_email = "webhook-bot@zulip.com" | ||||
|   | ||||
| @@ -98,7 +98,7 @@ def update_message_backend( | ||||
|     message_id: int = REQ(converter=to_non_negative_int, path_only=True), | ||||
|     stream_id: Optional[int] = REQ(converter=to_non_negative_int, default=None), | ||||
|     topic_name: Optional[str] = REQ_topic(), | ||||
|     propagate_mode: Optional[str] = REQ( | ||||
|     propagate_mode: str = REQ( | ||||
|         default="change_one", str_validator=check_string_in(PROPAGATE_MODE_VALUES) | ||||
|     ), | ||||
|     send_notification_to_old_thread: bool = REQ(default=True, json_validator=check_bool), | ||||
|   | ||||
| @@ -1,4 +1,5 @@ | ||||
| from django.http import HttpRequest | ||||
| from django.http.response import HttpResponse | ||||
| from django.utils.translation import gettext as _ | ||||
|  | ||||
| from zerver.decorator import webhook_view | ||||
| @@ -22,7 +23,7 @@ def api_slack_webhook( | ||||
|     channel_name: str = REQ(), | ||||
|     stream: str = REQ(default="slack"), | ||||
|     channels_map_to_topics: str = REQ(default="1"), | ||||
| ) -> HttpRequest: | ||||
| ) -> HttpResponse: | ||||
|  | ||||
|     if channels_map_to_topics not in list(VALID_OPTIONS.values()): | ||||
|         raise JsonableError(_("Error: channels_map_to_topics parameter other than 0 or 1")) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user