analytics: Add Composable type annotations.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2022-07-29 22:12:58 -07:00 committed by Tim Abbott
parent 2508b579a6
commit 73374996a5
2 changed files with 10 additions and 10 deletions

View File

@ -206,7 +206,7 @@ def do_aggregate_to_summary_table(
# Aggregate into RealmCount
output_table = stat.data_collector.output_table
if realm is not None:
realm_clause = SQL("AND zerver_realm.id = {}").format(Literal(realm.id))
realm_clause: Composable = SQL("AND zerver_realm.id = {}").format(Literal(realm.id))
else:
realm_clause = SQL("")
@ -357,7 +357,7 @@ def do_pull_by_sql_query(
) -> int:
if group_by is None:
subgroup: Composable = SQL("NULL")
group_by_clause = SQL("")
group_by_clause: Composable = SQL("")
else:
subgroup = Identifier(group_by[0]._meta.db_table, group_by[1])
group_by_clause = SQL(", {}").format(subgroup)
@ -443,7 +443,7 @@ def do_pull_minutes_active(
def count_message_by_user_query(realm: Optional[Realm]) -> QueryFn:
if realm is None:
realm_clause = SQL("")
realm_clause: Composable = SQL("")
else:
realm_clause = SQL("zerver_userprofile.realm_id = {} AND").format(Literal(realm.id))
return lambda kwargs: SQL(
@ -470,7 +470,7 @@ def count_message_by_user_query(realm: Optional[Realm]) -> QueryFn:
# Note: ignores the group_by / group_by_clause.
def count_message_type_by_user_query(realm: Optional[Realm]) -> QueryFn:
if realm is None:
realm_clause = SQL("")
realm_clause: Composable = SQL("")
else:
realm_clause = SQL("zerver_userprofile.realm_id = {} AND").format(Literal(realm.id))
return lambda kwargs: SQL(
@ -519,7 +519,7 @@ def count_message_type_by_user_query(realm: Optional[Realm]) -> QueryFn:
# table, consider writing a new query for efficiency.
def count_message_by_stream_query(realm: Optional[Realm]) -> QueryFn:
if realm is None:
realm_clause = SQL("")
realm_clause: Composable = SQL("")
else:
realm_clause = SQL("zerver_stream.realm_id = {} AND").format(Literal(realm.id))
return lambda kwargs: SQL(
@ -553,7 +553,7 @@ def count_message_by_stream_query(realm: Optional[Realm]) -> QueryFn:
# currently the only stat that uses this.
def count_user_by_realm_query(realm: Optional[Realm]) -> QueryFn:
if realm is None:
realm_clause = SQL("")
realm_clause: Composable = SQL("")
else:
realm_clause = SQL("zerver_userprofile.realm_id = {} AND").format(Literal(realm.id))
return lambda kwargs: SQL(
@ -583,7 +583,7 @@ def count_user_by_realm_query(realm: Optional[Realm]) -> QueryFn:
# In particular, it's important to ensure that migrations don't cause that to happen.
def check_realmauditlog_by_user_query(realm: Optional[Realm]) -> QueryFn:
if realm is None:
realm_clause = SQL("")
realm_clause: Composable = SQL("")
else:
realm_clause = SQL("realm_id = {} AND").format(Literal(realm.id))
return lambda kwargs: SQL(
@ -623,7 +623,7 @@ def check_realmauditlog_by_user_query(realm: Optional[Realm]) -> QueryFn:
def check_useractivityinterval_by_user_query(realm: Optional[Realm]) -> QueryFn:
if realm is None:
realm_clause = SQL("")
realm_clause: Composable = SQL("")
else:
realm_clause = SQL("zerver_userprofile.realm_id = {} AND").format(Literal(realm.id))
return lambda kwargs: SQL(
@ -647,7 +647,7 @@ def check_useractivityinterval_by_user_query(realm: Optional[Realm]) -> QueryFn:
def count_realm_active_humans_query(realm: Optional[Realm]) -> QueryFn:
if realm is None:
realm_clause = SQL("")
realm_clause: Composable = SQL("")
else:
realm_clause = SQL("realm_id = {} AND").format(Literal(realm.id))
return lambda kwargs: SQL(

View File

@ -410,7 +410,7 @@ def ad_hoc_queries() -> List[Dict[str, str]]:
for mobile_type in ["Android", "ZulipiOS"]:
title = f"{mobile_type} usage"
query = SQL(
query: Composable = SQL(
"""
select
realm.string_id,