Skip to content

[DEV-13128] fix: bad runtime typing #363

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: 6.14.1.rc
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion indico/http/serialization.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
"""
Handles deserialization / decoding of responses
"""

import gzip
import io
import json
import logging
import traceback
from collections import defaultdict
from email.message import EmailMessage
from typing import Dict, Tuple

from indico.errors import IndicoDecodingError

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


async def aio_deserialize(response, force_json=False, force_decompress=False):
content_type, params = parse_header(response.headers.get("Content-Type"))
content = await response.read()
Expand All @@ -63,11 +66,13 @@ async def aio_deserialize(response, force_json=False, force_decompress=False):
content_type, charset, content.decode("ascii", "ignore")
)

def parse_header(header: str) -> tuple[str, dict[str, str]]:

def parse_header(header: str) -> Tuple[str, Dict[str, str]]:
email = EmailMessage()
email["Content-Type"] = header
return email.get_content_type(), email["Content-Type"].params


def raw_bytes(content, *args, **kwargs):
return content

Expand Down
10 changes: 6 additions & 4 deletions indico/queries/model_export.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import List, Optional, Union

from indico.client.request import Delay, GraphQLRequest, RequestChain
from indico.types.model_export import ModelExport

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

previous: ModelExport | None = None
previous: Optional[ModelExport] = None

def __init__(
self,
model_id: int,
wait: bool = True,
request_interval: int | float = 5,
request_interval: Union[int, float] = 5,
):
self.wait = wait
self.model_id = model_id
Expand Down Expand Up @@ -91,14 +93,14 @@ class GetModelExports(GraphQLRequest):
"createdBy",
]

def __init__(self, export_ids: list[int], with_signed_url: bool = False):
def __init__(self, export_ids: List[int], with_signed_url: bool = False):
if with_signed_url:
self._base_fields.append("signedUrl")

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

def process_response(self, response) -> list[ModelExport]:
def process_response(self, response) -> List[ModelExport]:
return [
ModelExport(**export)
for export in super().process_response(response)["modelExports"][
Expand Down
9 changes: 6 additions & 3 deletions indico/queries/model_import.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Generator
from typing import Generator, Optional, Union

import requests

Expand Down Expand Up @@ -100,7 +100,10 @@ class UploadStaticModelExport(RequestChain):
"""

def __init__(
self, file_path: str, auto_process: bool = False, workflow_id: int | None = None
self,
file_path: str,
auto_process: bool = False,
workflow_id: Optional[int] = None,
):
self.file_path = file_path
self.auto_process = auto_process
Expand All @@ -111,7 +114,7 @@ def __init__(

self.workflow_id = workflow_id

def requests(self) -> Generator[str | Job, None, None]:
def requests(self) -> Generator[Union[str, Job], None, None]:
if self.auto_process:
yield _UploadSMExport(self.file_path)
yield ProcessStaticModelExport(
Expand Down
2 changes: 1 addition & 1 deletion indico/queries/submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ class SubmitReview(GraphQLRequest):
def __init__(
self,
submission: Union[int, Submission],
changes: Dict | List = None,
changes: Union[Dict, List] = None,
rejected: bool = False,
force_complete: bool = None,
):
Expand Down
14 changes: 7 additions & 7 deletions indico/queries/workflow_components.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, List
from typing import Any, Dict, List, Optional

import jsons

Expand Down Expand Up @@ -71,7 +71,7 @@ def __init__(
after_component_link: int,
workflow_id: int,
component: dict,
blueprint_id: int | None = None,
blueprint_id: Optional[int] = None,
):
super().__init__(
self.query,
Expand Down Expand Up @@ -464,12 +464,12 @@ class AddStaticModelComponent(RequestChain):
def __init__(
self,
workflow_id: int,
after_component_id: int | None = None,
after_component_link_id: int | None = None,
static_component_config: dict[str, Any] | None = None,
component_name: str | None = None,
after_component_id: Optional[int] = None,
after_component_link_id: Optional[int] = None,
static_component_config: Optional[Dict[str, Any]] = None,
component_name: Optional[str] = None,
auto_process: bool = False,
export_file: str | None = None,
export_file: Optional[str] = None,
):
if not export_file and auto_process:
raise IndicoInputError("Must provide export_file if auto_process is True.")
Expand Down