Skip to content

Commit 411049d

Browse files
[DEV-13128] fix: bad runtime typing (#363)
1 parent 049d802 commit 411049d

File tree

5 files changed

+26
-16
lines changed

5 files changed

+26
-16
lines changed

indico/http/serialization.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
"""
22
Handles deserialization / decoding of responses
33
"""
4+
45
import gzip
56
import io
67
import json
78
import logging
89
import traceback
910
from collections import defaultdict
1011
from email.message import EmailMessage
12+
from typing import Dict, Tuple
1113

1214
from indico.errors import IndicoDecodingError
1315

@@ -42,6 +44,7 @@ def deserialize(response, force_json=False, force_decompress=False):
4244
content_type, charset, content.decode("ascii", "ignore")
4345
)
4446

47+
4548
async def aio_deserialize(response, force_json=False, force_decompress=False):
4649
content_type, params = parse_header(response.headers.get("Content-Type"))
4750
content = await response.read()
@@ -63,11 +66,13 @@ async def aio_deserialize(response, force_json=False, force_decompress=False):
6366
content_type, charset, content.decode("ascii", "ignore")
6467
)
6568

66-
def parse_header(header: str) -> tuple[str, dict[str, str]]:
69+
70+
def parse_header(header: str) -> Tuple[str, Dict[str, str]]:
6771
email = EmailMessage()
6872
email["Content-Type"] = header
6973
return email.get_content_type(), email["Content-Type"].params
7074

75+
7176
def raw_bytes(content, *args, **kwargs):
7277
return content
7378

indico/queries/model_export.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing import List, Optional, Union
2+
13
from indico.client.request import Delay, GraphQLRequest, RequestChain
24
from indico.types.model_export import ModelExport
35

@@ -36,13 +38,13 @@ class CreateModelExport(RequestChain):
3638
request_interval (int | float): the interval between requests in seconds. Defaults to 5.
3739
"""
3840

39-
previous: ModelExport | None = None
41+
previous: Optional[ModelExport] = None
4042

4143
def __init__(
4244
self,
4345
model_id: int,
4446
wait: bool = True,
45-
request_interval: int | float = 5,
47+
request_interval: Union[int, float] = 5,
4648
):
4749
self.wait = wait
4850
self.model_id = model_id
@@ -91,14 +93,14 @@ class GetModelExports(GraphQLRequest):
9193
"createdBy",
9294
]
9395

94-
def __init__(self, export_ids: list[int], with_signed_url: bool = False):
96+
def __init__(self, export_ids: List[int], with_signed_url: bool = False):
9597
if with_signed_url:
9698
self._base_fields.append("signedUrl")
9799

98100
query_with_fields = self.query.replace("{fields}", "\n".join(self._base_fields))
99101
super().__init__(query_with_fields, variables={"exportIds": export_ids})
100102

101-
def process_response(self, response) -> list[ModelExport]:
103+
def process_response(self, response) -> List[ModelExport]:
102104
return [
103105
ModelExport(**export)
104106
for export in super().process_response(response)["modelExports"][

indico/queries/model_import.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Generator
1+
from typing import Generator, Optional, Union
22

33
import requests
44

@@ -100,7 +100,10 @@ class UploadStaticModelExport(RequestChain):
100100
"""
101101

102102
def __init__(
103-
self, file_path: str, auto_process: bool = False, workflow_id: int | None = None
103+
self,
104+
file_path: str,
105+
auto_process: bool = False,
106+
workflow_id: Optional[int] = None,
104107
):
105108
self.file_path = file_path
106109
self.auto_process = auto_process
@@ -111,7 +114,7 @@ def __init__(
111114

112115
self.workflow_id = workflow_id
113116

114-
def requests(self) -> Generator[str | Job, None, None]:
117+
def requests(self) -> Generator[Union[str, Job], None, None]:
115118
if self.auto_process:
116119
yield _UploadSMExport(self.file_path)
117120
yield ProcessStaticModelExport(

indico/queries/submission.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ class SubmitReview(GraphQLRequest):
490490
def __init__(
491491
self,
492492
submission: Union[int, Submission],
493-
changes: Dict | List = None,
493+
changes: Union[Dict, List] = None,
494494
rejected: bool = False,
495495
force_complete: bool = None,
496496
):

indico/queries/workflow_components.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, List
1+
from typing import Any, Dict, List, Optional
22

33
import jsons
44

@@ -71,7 +71,7 @@ def __init__(
7171
after_component_link: int,
7272
workflow_id: int,
7373
component: dict,
74-
blueprint_id: int | None = None,
74+
blueprint_id: Optional[int] = None,
7575
):
7676
super().__init__(
7777
self.query,
@@ -464,12 +464,12 @@ class AddStaticModelComponent(RequestChain):
464464
def __init__(
465465
self,
466466
workflow_id: int,
467-
after_component_id: int | None = None,
468-
after_component_link_id: int | None = None,
469-
static_component_config: dict[str, Any] | None = None,
470-
component_name: str | None = None,
467+
after_component_id: Optional[int] = None,
468+
after_component_link_id: Optional[int] = None,
469+
static_component_config: Optional[Dict[str, Any]] = None,
470+
component_name: Optional[str] = None,
471471
auto_process: bool = False,
472-
export_file: str | None = None,
472+
export_file: Optional[str] = None,
473473
):
474474
if not export_file and auto_process:
475475
raise IndicoInputError("Must provide export_file if auto_process is True.")

0 commit comments

Comments
 (0)