1- from typing import Generator
1+ from typing import TYPE_CHECKING , cast
22
33import requests
44
55from indico .client .request import GraphQLRequest , RequestChain
66from indico .errors import IndicoInputError , IndicoRequestError
7- from indico .queries .jobs import JobStatus
87from indico .types .jobs import Job
98
9+ from .jobs import JobStatus
1010
11- class _UploadSMExport (GraphQLRequest ):
11+ if TYPE_CHECKING : # pragma: no cover
12+ from typing import Dict , Iterator , Optional , Union # noqa: F401
13+
14+ from indico .typing import Payload
15+
16+
17+ class _UploadSMExport (GraphQLRequest [str ]):
1218 query = """
1319 query exportUpload {
1420 exportUpload {
@@ -22,25 +28,26 @@ def __init__(self, file_path: str):
2228 self .file_path = file_path
2329 super ().__init__ (self .query )
2430
25- def process_response (self , response ) -> str :
26- resp = super ().process_response (response )["exportUpload" ]
31+ def process_response (self , response : "Payload" ) -> str :
32+ resp : "Dict[str, str]" = super ().parse_payload (response )["exportUpload" ]
2733 signed_url = resp ["signedUrl" ]
2834 storage_uri = resp ["storageUri" ]
2935
3036 with open (self .file_path , "rb" ) as file :
3137 file_content = file .read ()
3238
3339 headers = {"Content-Type" : "application/zip" }
34- response = requests .put (signed_url , data = file_content , headers = headers )
40+ export_response = requests .put (signed_url , data = file_content , headers = headers )
3541
36- if response .status_code != 200 :
42+ if export_response .status_code != 200 :
3743 raise IndicoRequestError (
38- f"Failed to upload static model export: { response .text } "
44+ f"Failed to upload static model export: { export_response .text } " ,
45+ export_response .status_code ,
3946 )
4047 return storage_uri
4148
4249
43- class ProcessStaticModelExport (GraphQLRequest ):
50+ class ProcessStaticModelExport (GraphQLRequest [ "Job" ] ):
4451 """
4552 Process a static model export.
4653
@@ -77,12 +84,12 @@ def __init__(
7784 },
7885 )
7986
80- def process_response (self , response ) -> Job :
81- job_id = super ().process_response (response )["processStaticModelExport" ]["jobId" ]
87+ def process_response (self , response : "Payload" ) -> Job :
88+ job_id = super ().parse_payload (response )["processStaticModelExport" ]["jobId" ]
8289 return Job (id = job_id )
8390
8491
85- class UploadStaticModelExport (RequestChain ):
92+ class UploadStaticModelExport (RequestChain [ "Union[Job, str]" ] ):
8693 """
8794 Upload a static model export to Indico.
8895
@@ -100,22 +107,27 @@ class UploadStaticModelExport(RequestChain):
100107 """
101108
102109 def __init__ (
103- self , file_path : str , auto_process : bool = False , workflow_id : int | None = None
110+ self ,
111+ file_path : str ,
112+ auto_process : bool = False ,
113+ workflow_id : "Optional[int]" = None ,
104114 ):
105- self .file_path = file_path
106- self .auto_process = auto_process
107- if auto_process and not workflow_id :
115+ if auto_process and workflow_id is None :
108116 raise IndicoInputError (
109117 "Must provide `workflow_id` if `auto_process` is True."
110118 )
111119
120+ self .file_path = file_path
121+ self .auto_process = auto_process
112122 self .workflow_id = workflow_id
113123
114- def requests (self ) -> Generator [str | Job , None , None ]:
124+ def requests (
125+ self ,
126+ ) -> "Iterator[Union[_UploadSMExport, ProcessStaticModelExport, JobStatus]]" :
115127 if self .auto_process :
116128 yield _UploadSMExport (self .file_path )
117129 yield ProcessStaticModelExport (
118- storage_uri = self .previous , workflow_id = self .workflow_id
130+ storage_uri = self .previous , workflow_id = cast ( int , self .workflow_id )
119131 )
120132 yield JobStatus (self .previous .id )
121133 if self .previous .status == "FAILURE" :
0 commit comments