Skip to content

Commit 44628ec

Browse files
committed
Server: add type hints to _query
1 parent be8fa2c commit 44628ec

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/server/_query.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
Sequence,
1010
Tuple,
1111
Union,
12-
cast
12+
cast,
1313
)
14+
from flask import Response
1415

1516
from sqlalchemy import text
1617
from sqlalchemy.engine import Row
@@ -53,7 +54,7 @@ def filter_values(
5354
param_key: str,
5455
params: Dict[str, Any],
5556
formatter=lambda x: x,
56-
):
57+
) -> str:
5758
if not values:
5859
return "FALSE"
5960
# builds a SQL expression to filter strings (ex: locations)
@@ -68,7 +69,7 @@ def filter_strings(
6869
values: Optional[Sequence[str]],
6970
param_key: str,
7071
params: Dict[str, Any],
71-
):
72+
) -> str:
7273
return filter_values(field, values, param_key, params)
7374

7475

@@ -77,7 +78,7 @@ def filter_integers(
7778
values: Optional[Sequence[IntRange]],
7879
param_key: str,
7980
params: Dict[str, Any],
80-
):
81+
) -> str:
8182
return filter_values(field, values, param_key, params)
8283

8384

@@ -86,7 +87,7 @@ def filter_dates(
8687
values: Optional[TimeValues],
8788
param_key: str,
8889
params: Dict[str, Any],
89-
):
90+
) -> str:
9091
ranges = time_values_to_ranges(values)
9192
return filter_values(field, ranges, param_key, params, date_string)
9293

@@ -198,7 +199,7 @@ def parse_row(
198199
fields_string: Optional[Sequence[str]] = None,
199200
fields_int: Optional[Sequence[str]] = None,
200201
fields_float: Optional[Sequence[str]] = None,
201-
):
202+
) -> Dict[str, Any]:
202203
keys = set(row.keys())
203204
parsed = dict()
204205
if fields_string:
@@ -234,7 +235,7 @@ def limit_query(query: str, limit: int) -> str:
234235
return full_query
235236

236237

237-
def run_query(p: APrinter, query_tuple: Tuple[str, Dict[str, Any]]):
238+
def run_query(p: APrinter, query_tuple: Tuple[str, Dict[str, Any]]) -> Iterable[Row]:
238239
query, params = query_tuple
239240
# limit rows + 1 for detecting whether we would have more
240241
full_query = text(limit_query(query, p.remaining_rows + 1))
@@ -254,7 +255,7 @@ def execute_queries(
254255
fields_int: Sequence[str],
255256
fields_float: Sequence[str],
256257
transform: Callable[[Dict[str, Any], Row], Dict[str, Any]] = _identity_transform,
257-
):
258+
) -> Response:
258259
"""
259260
execute the given queries and return the response to send them
260261
"""
@@ -313,14 +314,14 @@ def execute_query(
313314
fields_int: Sequence[str],
314315
fields_float: Sequence[str],
315316
transform: Callable[[Dict[str, Any], Row], Dict[str, Any]] = _identity_transform,
316-
):
317+
) -> Response:
317318
"""
318319
execute the given query and return the response to send it
319320
"""
320321
return execute_queries([(query, params)], fields_string, fields_int, fields_float, transform)
321322

322323

323-
def _join_l(value: Union[str, List[str]]):
324+
def _join_l(value: Union[str, List[str]]) -> str:
324325
return ", ".join(value) if isinstance(value, (list, tuple)) else value
325326

326327

0 commit comments

Comments
 (0)