Skip to content

Commit f8de0ba

Browse files
committed
Server: add type hints to _query
1 parent dc26e55 commit f8de0ba

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
@@ -54,7 +55,7 @@ def filter_values(
5455
param_key: str,
5556
params: Dict[str, Any],
5657
formatter=lambda x: x,
57-
):
58+
) -> str:
5859
if not values:
5960
return "FALSE"
6061
# builds a SQL expression to filter strings (ex: locations)
@@ -69,7 +70,7 @@ def filter_strings(
6970
values: Optional[Sequence[str]],
7071
param_key: str,
7172
params: Dict[str, Any],
72-
):
73+
) -> str:
7374
return filter_values(field, values, param_key, params)
7475

7576

@@ -78,7 +79,7 @@ def filter_integers(
7879
values: Optional[Sequence[Union[Tuple[int, int], int]]],
7980
param_key: str,
8081
params: Dict[str, Any],
81-
):
82+
) -> str:
8283
return filter_values(field, values, param_key, params)
8384

8485

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

@@ -199,7 +200,7 @@ def parse_row(
199200
fields_string: Optional[Sequence[str]] = None,
200201
fields_int: Optional[Sequence[str]] = None,
201202
fields_float: Optional[Sequence[str]] = None,
202-
):
203+
) -> Dict[str, Any]:
203204
keys = set(row.keys())
204205
parsed = dict()
205206
if fields_string:
@@ -235,7 +236,7 @@ def limit_query(query: str, limit: int) -> str:
235236
return full_query
236237

237238

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

323324

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

327328

0 commit comments

Comments
 (0)