Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

typing: Amend inaccurate type annotations.

PIG208e517f967b8dc
diff --git a/analytics/urls.py b/analytics/urls.py
index affedf048b7..32ea0366fab 100644
--- a/analytics/urls.py
+++ b/analytics/urls.py
@@ -1,5 +1,8 @@
+from typing import List, Union
+
from django.conf.urls import include
from django.urls import path
+from django.urls.resolvers import URLPattern, URLResolver
from analytics.views.installation_activity import get_installation_activity
from analytics.views.realm_activity import get_realm_activity
@@ -19,7 +22,7 @@ from analytics.views.support import support
from analytics.views.user_activity import get_user_activity
from zerver.lib.rest import rest_path
-i18n_urlpatterns = [
+i18n_urlpatterns: List[Union[URLPattern, URLResolver]] = [
# Server admin (user_profile.is_staff) visible stats pages
path("activity", get_installation_activity),
path("activity/support", support, name="support"),
diff --git a/analytics/views/activity_common.py b/analytics/views/activity_common.py
index d752b01dddf..4b11d2f3293 100644
--- a/analytics/views/activity_common.py
+++ b/analytics/views/activity_common.py
@@ -5,7 +5,7 @@ from typing import Any, Dict, List, Optional, Sequence
import pytz
from django.conf import settings
-from django.db import connection
+from django.db.backends.utils import CursorWrapper
from django.db.models.query import QuerySet
from django.template import loader
from django.urls import reverse
@@ -39,7 +39,7 @@ def make_table(
return content
-def dictfetchall(cursor: connection.cursor) -> List[Dict[str, Any]]:
+def dictfetchall(cursor: CursorWrapper) -> List[Dict[str, Any]]:
"Returns all rows from a cursor as a dict"
desc = cursor.description
return [dict(zip((col[0] for col in desc), row)) for row in cursor.fetchall()]
diff --git a/analytics/views/installation_activity.py b/analytics/views/installation_activity.py
index 39dc6436a2a..5de2abf3866 100644
--- a/analytics/views/installation_activity.py
+++ b/analytics/views/installation_activity.py
@@ -369,7 +369,7 @@ def ad_hoc_queries() -> List[Dict[str, str]]:
cursor.close()
def fix_rows(
- i: int, fixup_func: Union[Callable[[Realm], mark_safe], Callable[[datetime], str]]
+ i: int, fixup_func: Union[Callable[[str], mark_safe], Callable[[datetime], str]]
) -> None:
for row in rows:
row[i] = fixup_func(row[i])
diff --git a/analytics/views/realm_activity.py b/analytics/views/realm_activity.py
index e1f53bc6463..d229a294d11 100644
--- a/analytics/views/realm_activity.py
+++ b/analytics/views/realm_activity.py
@@ -62,7 +62,7 @@ def realm_user_summary_table(
else:
return ""
- def is_recent(val: Optional[datetime]) -> bool:
+ def is_recent(val: datetime) -> bool:
age = timezone_now() - val
return age.total_seconds() < 5 * 60
diff --git a/zerver/decorator.py b/zerver/decorator.py
index 2407629a279..31d21c38c6b 100644
--- a/zerver/decorator.py
+++ b/zerver/decorator.py
@@ -814,14 +814,16 @@ def client_is_exempt_from_rate_limiting(request: HttpRequest) -> bool:
)
-def internal_notify_view(is_tornado_view: bool) -> Callable[[ViewFuncT], ViewFuncT]:
+def internal_notify_view(
+ is_tornado_view: bool,
+) -> Callable[[ViewFuncT], Callable[..., HttpResponse]]:
# The typing here could be improved by using the extended Callable types:
# https://mypy.readthedocs.io/en/stable/additional_features.html#extended-callable-types
"""Used for situations where something running on the Zulip server
needs to make a request to the (other) Django/Tornado processes running on
the server."""
- def _wrapped_view_func(view_func: ViewFuncT) -> ViewFuncT:
+ def _wrapped_view_func(view_func: ViewFuncT) -> Callable[..., HttpResponse]:
@csrf_exempt
@require_post
@wraps(view_func)
diff --git a/zerver/lib/actions.py b/zerver/lib/actions.py
index ab5707bca5a..1ef55c4aa03 100644
--- a/zerver/lib/actions.py
+++ b/zerver/lib/actions.py
@@ -1989,10 +1989,18 @@ def do_send_messages(
else:
user_list = list(user_ids)
- users: List[Dict[str, Union[int, List[str]]]] = []
+ UserData = TypedDict(
+ "UserData",
+ {
+ "id": int,
+ "flags": List[str],
+ "mentioned_user_group_id": Optional[int],
+ },
+ )
+ users: List[UserData] = []
for user_id in user_list:
flags = user_flags.get(user_id, [])
- user_data = dict(id=user_id, flags=flags)
+ user_data: UserData = dict(id=user_id, flags=flags, mentioned_user_group_id=None)
if user_id in send_request.mentioned_user_groups_map:
user_data["mentioned_user_group_id"] = send_request.mentioned_user_groups_map[
diff --git a/zilencer/management/commands/populate_db.py b/zilencer/management/commands/populate_db.py
index 9c6c13b9366..2393a6b5f7e 100644
--- a/zilencer/management/commands/populate_db.py
+++ b/zilencer/management/commands/populate_db.py
@@ -269,7 +269,7 @@ class Command(BaseCommand):
"data set for the backend tests.",
)
- def handle(self, **options: Any) -> None:
+ def handle(self, *args: Any, **options: Any) -> None:
# Suppress spammy output from the push notifications logger
push_notifications_logger.disabled = True