Skip to content

Commit

Permalink
Remove deprecated typing imports from generated SDK sources
Browse files Browse the repository at this point in the history
This is a continuation of cvat-ai#8626.
  • Loading branch information
SpecLad committed Nov 1, 2024
1 parent a4a989d commit 49d6899
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 43 deletions.
4 changes: 2 additions & 2 deletions cvat-sdk/gen/postprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ def make_api_name(self, name: str) -> str:
return underscore(name)

def make_type_annotation(self, type_repr: str) -> str:
type_repr = type_repr.replace("[", "typing.List[")
type_repr = type_repr.replace("[", "list[")
type_repr = type_repr.replace("(", "typing.Union[").replace(")", "]")
type_repr = type_repr.replace("{", "typing.Dict[").replace(":", ",").replace("}", "]")
type_repr = type_repr.replace("{", "dict[").replace(":", ",").replace("}", "]")

ANY_pattern = "bool, date, datetime, dict, float, int, list, str"
type_repr = type_repr.replace(ANY_pattern, "typing.Any")
Expand Down
4 changes: 2 additions & 2 deletions cvat-sdk/gen/templates/openapi-generator/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,10 @@ class {{classname}}(object):
_spec_property_naming: bool = False,
_content_type: typing.Optional[str] = None,
_host_index: typing.Optional[int] = None,
_request_auths: typing.Optional[typing.List] = None,
_request_auths: typing.Optional[list] = None,
_async_call: bool = False,
**kwargs,
) -> typing.Tuple[typing.Optional[{{>return_type}}], urllib3.HTTPResponse]:
) -> tuple[typing.Optional[{{>return_type}}], urllib3.HTTPResponse]:
"""{{{summary}}}{{^summary}}{{>operation_name}}{{/summary}} # noqa: E501

{{#notes}}
Expand Down
69 changes: 34 additions & 35 deletions cvat-sdk/gen/templates/openapi-generator/api_client.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ class ApiClient(object):

def __init__(self,
configuration: typing.Optional[Configuration] = None,
headers: typing.Optional[typing.Dict[str, str]] = None,
cookies: typing.Optional[typing.Dict[str, str]] = None,
headers: typing.Optional[dict[str, str]] = None,
cookies: typing.Optional[dict[str, str]] = None,
pool_threads: int = 1):
"""
:param configuration: configuration object for this client
Expand All @@ -85,7 +85,7 @@ class ApiClient(object):
self.pool_threads = pool_threads

self.rest_client = rest.RESTClientObject(configuration)
self.default_headers: typing.Dict[str, str] = headers or {}
self.default_headers: dict[str, str] = headers or {}
self.cookies = SimpleCookie()
if cookies:
self.cookies.update(cookies)
Expand Down Expand Up @@ -161,22 +161,22 @@ class ApiClient(object):
self,
resource_path: str,
method: str,
path_params: typing.Optional[typing.Dict[str, typing.Any]] = None,
query_params: typing.Optional[typing.List[typing.Tuple[str, typing.Any]]] = None,
header_params: typing.Optional[typing.Dict[str, typing.Any]] = None,
path_params: typing.Optional[dict[str, typing.Any]] = None,
query_params: typing.Optional[list[tuple[str, typing.Any]]] = None,
header_params: typing.Optional[dict[str, typing.Any]] = None,
body: typing.Optional[typing.Any] = None,
post_params: typing.Optional[typing.List[typing.Tuple[str, typing.Any]]] = None,
files: typing.Optional[typing.Dict[str, typing.List[io.IOBase]]] = None,
response_schema: typing.Optional[typing.Tuple[typing.Any]] = None,
auth_settings: typing.Optional[typing.List[str]] = None,
collection_formats: typing.Optional[typing.Dict[str, str]] = None,
post_params: typing.Optional[list[tuple[str, typing.Any]]] = None,
files: typing.Optional[dict[str, list[io.IOBase]]] = None,
response_schema: typing.Optional[tuple[typing.Any]] = None,
auth_settings: typing.Optional[list[str]] = None,
collection_formats: typing.Optional[dict[str, str]] = None,
*,
_parse_response: bool = True,
_request_timeout: typing.Optional[typing.Union[int, float, typing.Tuple]] = None,
_request_timeout: typing.Optional[typing.Union[int, float, tuple]] = None,
_host: typing.Optional[str] = None,
_check_type: typing.Optional[bool] = None,
_check_status: bool = True,
_request_auths: typing.Optional[typing.List[typing.Dict[str, typing.Any]]] = None
_request_auths: typing.Optional[list[dict[str, typing.Any]]] = None
):

config = self.configuration
Expand Down Expand Up @@ -271,7 +271,7 @@ class ApiClient(object):
return (return_data, response)
{{/tornado}}

def get_common_headers(self) -> typing.Dict[str, str]:
def get_common_headers(self) -> dict[str, str]:
"""
Returns a headers dict with all the required headers for requests
"""
Expand Down Expand Up @@ -324,7 +324,7 @@ class ApiClient(object):
"""
return to_json(obj, read_files=read_files)

def deserialize(self, response: HTTPResponse, response_schema: typing.Tuple, *, _check_type: bool):
def deserialize(self, response: HTTPResponse, response_schema: tuple, *, _check_type: bool):
"""Deserializes response into an object.

:param response (urllib3.HTTPResponse): object to be deserialized.
Expand Down Expand Up @@ -384,22 +384,22 @@ class ApiClient(object):
self,
resource_path: str,
method: str,
path_params: typing.Optional[typing.Dict[str, typing.Any]] = None,
query_params: typing.Optional[typing.List[typing.Tuple[str, typing.Any]]] = None,
header_params: typing.Optional[typing.Dict[str, typing.Any]] = None,
path_params: typing.Optional[dict[str, typing.Any]] = None,
query_params: typing.Optional[list[tuple[str, typing.Any]]] = None,
header_params: typing.Optional[dict[str, typing.Any]] = None,
body: typing.Optional[typing.Any] = None,
post_params: typing.Optional[typing.List[typing.Tuple[str, typing.Any]]] = None,
files: typing.Optional[typing.Dict[str, typing.List[io.IOBase]]] = None,
response_schema: typing.Optional[typing.Tuple[typing.Any]] = None,
auth_settings: typing.Optional[typing.List[str]] = None,
collection_formats: typing.Optional[typing.Dict[str, str]] = None,
post_params: typing.Optional[list[tuple[str, typing.Any]]] = None,
files: typing.Optional[dict[str, list[io.IOBase]]] = None,
response_schema: typing.Optional[tuple[typing.Any]] = None,
auth_settings: typing.Optional[list[str]] = None,
collection_formats: typing.Optional[dict[str, str]] = None,
*,
_async_call: typing.Optional[bool] = None,
_parse_response: bool = True,
_request_timeout: typing.Optional[typing.Union[int, float, typing.Tuple]] = None,
_request_timeout: typing.Optional[typing.Union[int, float, tuple]] = None,
_host: typing.Optional[str] = None,
_check_type: typing.Optional[bool] = None,
_request_auths: typing.Optional[typing.List[typing.Dict[str, typing.Any]]] = None,
_request_auths: typing.Optional[list[dict[str, typing.Any]]] = None,
_check_status: bool = True,
):
"""Makes the HTTP request (synchronous) and returns deserialized data.
Expand Down Expand Up @@ -580,7 +580,7 @@ class ApiClient(object):
new_params.append((k, v))
return new_params

def _serialize_file(self, file_instance: io.IOBase) -> typing.Tuple[str, typing.Union[str, bytes], str]:
def _serialize_file(self, file_instance: io.IOBase) -> tuple[str, typing.Union[str, bytes], str]:
if file_instance.closed is True:
raise ApiValueError("Cannot read a closed file.")
filename = os.path.basename(file_instance.name)
Expand All @@ -592,8 +592,7 @@ class ApiClient(object):
return filename, filedata, mimetype

def files_parameters(self,
files: typing.Optional[typing.Dict[str,
typing.List[io.IOBase]]] = None):
files: typing.Optional[dict[str, list[io.IOBase]]] = None):
"""Builds form parameters.

:param files: None or a dict with key=param_name and
Expand Down Expand Up @@ -714,7 +713,7 @@ class ApiClient(object):
{{#apiInfo}}{{#apis}}
{{>api_name}}: '{{classname}}'{{/apis}}{{/apiInfo}}

_apis: typing.Dict[str, object] = { {{#apiInfo}}{{#apis}}
_apis: dict[str, object] = { {{#apiInfo}}{{#apis}}
'{{>api_name}}': [None, '{{classname}}'],{{/apis}}{{/apiInfo}}
}

Expand All @@ -739,10 +738,10 @@ class ApiClient(object):

class Endpoint(object):
def __init__(self,
settings: typing.Optional[typing.Dict[str, typing.Any]] = None,
params_map: typing.Optional[typing.Dict[str, typing.Any]] = None,
root_map: typing.Optional[typing.Dict[str, typing.Any]] = None,
headers_map: typing.Optional[typing.Dict[str, typing.Any]] = None,
settings: typing.Optional[dict[str, typing.Any]] = None,
params_map: typing.Optional[dict[str, typing.Any]] = None,
root_map: typing.Optional[dict[str, typing.Any]] = None,
headers_map: typing.Optional[dict[str, typing.Any]] = None,
api_client: typing.Optional[ApiClient] = None
):
"""Creates an endpoint
Expand Down Expand Up @@ -897,9 +896,9 @@ class Endpoint(object):
_spec_property_naming: bool = False,
_content_type: typing.Optional[str] = None,
_host_index: typing.Optional[int] = None,
_request_auths: typing.Optional[typing.List] = None,
_request_auths: typing.Optional[list] = None,
_async_call: bool = False,
**kwargs) -> typing.Tuple[typing.Optional[typing.Any], HTTPResponse]:
**kwargs) -> tuple[typing.Optional[typing.Any], HTTPResponse]:
"""
Keyword Args:
endpoint args
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ class Configuration:

def __init__(self,
host: typing.Optional[str] = None,
api_key: typing.Optional[typing.Dict[str, str]] = None,
api_key_prefix: typing.Optional[typing.Dict[str, str]] = None,
api_key: typing.Optional[dict[str, str]] = None,
api_key_prefix: typing.Optional[dict[str, str]] = None,
username: typing.Optional[str] = None,
password: typing.Optional[str]=None,
discard_unknown_keys: bool = False,
Expand All @@ -179,9 +179,9 @@ class Configuration:
signing_info=None,
{{/hasHttpSignatureMethods}}
server_index: typing.Optional[int] = None,
server_variables: typing.Optional[typing.Dict[str, str]] = None,
server_variables: typing.Optional[dict[str, str]] = None,
server_operation_index: typing.Optional[int] = None,
server_operation_variables: typing.Optional[typing.Dict[str, str]] = None,
server_operation_variables: typing.Optional[dict[str, str]] = None,
ssl_ca_cert: typing.Optional[str] = None,
verify_ssl: typing.Optional[bool] = None,
) -> None:
Expand Down

0 comments on commit 49d6899

Please sign in to comment.