Skip to content

Commit 15b5db6

Browse files
committed
Fix typings
1 parent 8a675a3 commit 15b5db6

File tree

3 files changed

+22
-17
lines changed

3 files changed

+22
-17
lines changed

qfieldcloud_sdk/cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def logout(ctx):
177177
help="Includes the public project in the list. Default: False",
178178
)
179179
@click.pass_context
180-
def list_projects(ctx, include_public, **opts):
180+
def list_projects(ctx, include_public: bool, **opts) -> None:
181181
"""List QFieldCloud projects."""
182182

183183
log("Listing projects…")
@@ -396,7 +396,7 @@ def list_jobs(ctx, project_id, job_type: Optional[sdk.JobTypes], **opts):
396396

397397
log(f'Listing project "{project_id}" jobs…')
398398

399-
jobs: List[Dict[Any]] = ctx.obj["client"].list_jobs(
399+
jobs: List[Dict] = ctx.obj["client"].list_jobs(
400400
project_id,
401401
job_type,
402402
sdk.Pagination(**opts),

qfieldcloud_sdk/interfaces.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import json
2-
from typing import Any, List, Union
2+
from typing import Any
33

44
import requests
55

@@ -37,7 +37,7 @@ def __init__(self, **kwargs):
3737
self.headers["X-Previous-Page"] = prev_url
3838
self.headers["X-Next-Page"] = next_url
3939

40-
def json(self) -> Union[QfcMockItem, List[QfcMockItem]]:
40+
def json(self):
4141
if self.request_kwargs["method"] == "GET":
4242
return [QfcMockItem(id=n) for n in range(self.total)]
4343
else:
@@ -69,7 +69,7 @@ def __init__(self, response: requests.Response, *args):
6969
except Exception:
7070
json_content = ""
7171

72-
self.reason = f'Requested "{response.url}" and got "{response.status_code} {response.reason}":\n{json_content or response.content}'
72+
self.reason = f'Requested "{response.url}" and got "{response.status_code} {response.reason}":\n{json_content or response.content.decode()}'
7373

7474
def __str__(self) -> str:
7575
return self.reason

qfieldcloud_sdk/sdk.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import sys
55
from enum import Enum
66
from pathlib import Path
7-
from typing import Any, Callable, Dict, List, Optional, Union
7+
from typing import Any, Callable, Dict, List, Optional, Union, cast
88
from urllib import parse as urlparse
99

1010
import requests
@@ -136,13 +136,13 @@ def list_projects(
136136
their own and optionally the public ones.
137137
"""
138138
params = {
139-
"include-public": int(include_public),
139+
"include-public": str(int(include_public)), # type: ignore
140140
}
141141

142142
payload = self._request_json(
143143
"GET", "projects", params=params, pagination=pagination
144144
)
145-
return payload
145+
return cast(List, payload)
146146

147147
def list_remote_files(
148148
self, project_id: str, skip_metadata: bool = True
@@ -337,7 +337,7 @@ def list_jobs(
337337
"""
338338
Returns a paginated lists of jobs accessible to the user.
339339
"""
340-
return self._request_json(
340+
payload = self._request_json(
341341
"GET",
342342
"jobs/",
343343
{
@@ -346,6 +346,7 @@ def list_jobs(
346346
},
347347
pagination=pagination,
348348
)
349+
return cast(List, payload)
349350

350351
def job_trigger(
351352
self, project_id: str, job_type: JobTypes, force: bool = False
@@ -580,7 +581,7 @@ def download_file(
580581
remote_filename: Path,
581582
show_progress: bool,
582583
remote_etag: str = None,
583-
) -> requests.Response:
584+
) -> Optional[requests.Response]:
584585
"""Download a single project file.
585586
586587
Args:
@@ -595,7 +596,7 @@ def download_file(
595596
NotImplementedError: Raised if unknown `download_type` is passed
596597
597598
Returns:
598-
requests.Response: the response object
599+
requests.Response | None: the response object
599600
"""
600601

601602
if remote_etag and local_filename.exists():
@@ -608,7 +609,7 @@ def download_file(
608609
logger.info(
609610
f'Skipping download of "{remote_filename}" because it is already present locally'
610611
)
611-
return
612+
return None
612613

613614
if download_type == FileTransferType.PROJECT:
614615
url = f"files/{project_id}/{remote_filename}"
@@ -692,7 +693,7 @@ def _request_json(
692693
allow_redirects=None,
693694
pagination: Pagination = Pagination(),
694695
) -> Union[List, Dict]:
695-
result = None
696+
result: Optional[Union[List, Dict]] = None
696697
is_empty_pagination = pagination.is_empty
697698

698699
while True:
@@ -712,11 +713,15 @@ def _request_json(
712713
payload = resp.json()
713714

714715
if isinstance(payload, list):
716+
result = cast(List, result)
717+
715718
if result:
716719
result += payload
717720
else:
718721
result = payload
719722
elif isinstance(payload, dict):
723+
result = cast(Dict, result)
724+
720725
if result:
721726
result = {**result, **payload}
722727
else:
@@ -735,8 +740,8 @@ def _request_json(
735740

736741
query_params = urlparse.parse_qs(urlparse.urlparse(next_url).query)
737742
pagination = Pagination(
738-
limit=query_params["limit"],
739-
offset=query_params["offset"],
743+
limit=cast(int, query_params["limit"]),
744+
offset=cast(int, query_params["offset"]),
740745
)
741746

742747
return result
@@ -782,8 +787,8 @@ def _request(
782787
offset = pagination.offset or 0
783788
params = {
784789
**params,
785-
"limit": limit,
786-
"offset": offset,
790+
"limit": str(limit),
791+
"offset": str(offset),
787792
}
788793

789794
request_params = {

0 commit comments

Comments
 (0)