44import sys
55from enum import Enum
66from pathlib import Path
7- from typing import Any , Callable , Dict , List , Optional , Union
7+ from typing import Any , Callable , Dict , List , Optional , Union , cast
88from urllib import parse as urlparse
99
1010import 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