Skip to content

Commit 3b11c36

Browse files
PIG208timabbott
authored andcommitted
typing: Fix function signatures.
This fixes mypy errors for function signatures discovered with django-stubs.
1 parent 7142723 commit 3b11c36

File tree

7 files changed

+14
-12
lines changed

7 files changed

+14
-12
lines changed

zerver/filters.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import re
2-
from typing import Any, Dict
2+
from typing import Any, Dict, Optional
33

44
from django.http import HttpRequest
55
from django.views.debug import SafeExceptionReporterFilter
66

77

88
class ZulipExceptionReporterFilter(SafeExceptionReporterFilter):
9-
def get_post_parameters(self, request: HttpRequest) -> Dict[str, Any]:
9+
def get_post_parameters(self, request: Optional[HttpRequest]) -> Dict[str, Any]:
1010
post_data = SafeExceptionReporterFilter.get_post_parameters(self, request)
1111
assert isinstance(post_data, dict)
1212
filtered_post = post_data.copy()

zerver/lib/actions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2924,7 +2924,7 @@ def check_update_message(
29242924
message_id: int,
29252925
stream_id: Optional[int] = None,
29262926
topic_name: Optional[str] = None,
2927-
propagate_mode: Optional[str] = "change_one",
2927+
propagate_mode: str = "change_one",
29282928
send_notification_to_old_thread: bool = True,
29292929
send_notification_to_new_thread: bool = True,
29302930
content: Optional[str] = None,

zerver/lib/presence.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import itertools
33
import time
44
from collections import defaultdict
5-
from typing import Any, Dict, List, Set
5+
from typing import Any, Dict, Mapping, Sequence, Set
66

77
from django.utils.timezone import now as timezone_now
88

@@ -11,7 +11,7 @@
1111

1212

1313
def get_status_dicts_for_rows(
14-
all_rows: List[Dict[str, Any]], mobile_user_ids: Set[int], slim_presence: bool
14+
all_rows: Sequence[Mapping[str, Any]], mobile_user_ids: Set[int], slim_presence: bool
1515
) -> Dict[str, Dict[str, Any]]:
1616

1717
# Note that datetime values have sub-second granularity, which is
@@ -46,7 +46,7 @@ def get_status_dicts_for_rows(
4646

4747

4848
def get_modern_user_info(
49-
presence_rows: List[Dict[str, Any]], mobile_user_ids: Set[int]
49+
presence_rows: Sequence[Mapping[str, Any]], mobile_user_ids: Set[int]
5050
) -> Dict[str, Any]:
5151

5252
active_timestamp = None
@@ -76,7 +76,7 @@ def get_modern_user_info(
7676

7777

7878
def get_legacy_user_info(
79-
presence_rows: List[Dict[str, Any]], mobile_user_ids: Set[int]
79+
presence_rows: Sequence[Mapping[str, Any]], mobile_user_ids: Set[int]
8080
) -> Dict[str, Any]:
8181

8282
# The format of data here is for legacy users of our API,

zerver/lib/test_runner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ def __init__(self, *args: Any, **kwargs: Any) -> None:
297297
self.shallow_tested_templates: Set[str] = set()
298298
template_rendered.connect(self.on_template_rendered)
299299

300-
def get_resultclass(self) -> Type[TestResult]:
300+
def get_resultclass(self) -> Optional[Type[TextTestResult]]:
301301
return TextTestResult
302302

303303
def on_template_rendered(self, sender: Any, context: Dict[str, Any], **kwargs: Any) -> None:

zerver/tests/test_webhooks_common.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from unittest.mock import MagicMock, patch
44

55
from django.http import HttpRequest
6+
from django.http.response import HttpResponse
67

78
from zerver.decorator import webhook_view
89
from zerver.lib.actions import do_rename_stream
@@ -61,11 +62,11 @@ def test_webhook_http_header_header_does_not_exist(self) -> None:
6162

6263
def test_notify_bot_owner_on_invalid_json(self) -> None:
6364
@webhook_view("ClientName", notify_bot_owner_on_invalid_json=False)
64-
def my_webhook_no_notify(request: HttpRequest, user_profile: UserProfile) -> None:
65+
def my_webhook_no_notify(request: HttpRequest, user_profile: UserProfile) -> HttpResponse:
6566
raise InvalidJSONError("Malformed JSON")
6667

6768
@webhook_view("ClientName", notify_bot_owner_on_invalid_json=True)
68-
def my_webhook_notify(request: HttpRequest, user_profile: UserProfile) -> None:
69+
def my_webhook_notify(request: HttpRequest, user_profile: UserProfile) -> HttpResponse:
6970
raise InvalidJSONError("Malformed JSON")
7071

7172
webhook_bot_email = "[email protected]"

zerver/views/message_edit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def update_message_backend(
9898
message_id: int = REQ(converter=to_non_negative_int, path_only=True),
9999
stream_id: Optional[int] = REQ(converter=to_non_negative_int, default=None),
100100
topic_name: Optional[str] = REQ_topic(),
101-
propagate_mode: Optional[str] = REQ(
101+
propagate_mode: str = REQ(
102102
default="change_one", str_validator=check_string_in(PROPAGATE_MODE_VALUES)
103103
),
104104
send_notification_to_old_thread: bool = REQ(default=True, json_validator=check_bool),

zerver/webhooks/slack/view.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from django.http import HttpRequest
2+
from django.http.response import HttpResponse
23
from django.utils.translation import gettext as _
34

45
from zerver.decorator import webhook_view
@@ -22,7 +23,7 @@ def api_slack_webhook(
2223
channel_name: str = REQ(),
2324
stream: str = REQ(default="slack"),
2425
channels_map_to_topics: str = REQ(default="1"),
25-
) -> HttpRequest:
26+
) -> HttpResponse:
2627

2728
if channels_map_to_topics not in list(VALID_OPTIONS.values()):
2829
raise JsonableError(_("Error: channels_map_to_topics parameter other than 0 or 1"))

0 commit comments

Comments
 (0)