Skip to content

Commit

Permalink
typing: Amend inaccurate type annotations.
Browse files Browse the repository at this point in the history
This amend some type annotations that turn out to be inaccurate with
django-stubs.
  • Loading branch information
PIG208 committed Jul 26, 2021
1 parent 3267e90 commit acfdcff
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 9 deletions.
5 changes: 4 additions & 1 deletion analytics/urls.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -19,7 +22,7 @@
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"),
Expand Down
4 changes: 2 additions & 2 deletions analytics/views/activity_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

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
Expand Down Expand Up @@ -39,7 +39,7 @@ def fix_row(row: Any) -> Dict[str, Any]:
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()]
Expand Down
2 changes: 1 addition & 1 deletion analytics/views/installation_activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ def get_page(
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])
Expand Down
2 changes: 1 addition & 1 deletion analytics/views/realm_activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def get_count(user_summary: Dict[str, Dict[str, str]], k: str) -> str:
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

Expand Down
6 changes: 4 additions & 2 deletions zerver/decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion zerver/lib/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1986,7 +1986,7 @@ def do_send_messages(
else:
user_list = list(user_ids)

users: List[Dict[str, Union[int, List[str]]]] = []
users: List[Dict[str, object]] = []
for user_id in user_list:
flags = user_flags.get(user_id, [])
user_data = dict(id=user_id, flags=flags)
Expand Down
2 changes: 1 addition & 1 deletion zilencer/management/commands/populate_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def add_arguments(self, parser: CommandParser) -> None:
"data set for the backend tests.",
)

def handle(self, **options: Any) -> None:
def handle(self, *args: Any, **options: Any) -> None:
if options["percent_huddles"] + options["percent_personals"] > 100:
self.stderr.write("Error! More than 100% of messages allocated.\n")
return
Expand Down

0 comments on commit acfdcff

Please sign in to comment.