python: type API client internal structures (#16692)

* In samples/openapi3/client/petstore/python, this reduces the mypy errors from 435 to 178 errors
* In samples/openapi3/client/petstore/python-aiohttp, this reduces the mypy errors from 381 to 124 errors
* In samples/client/echo_api/python, this reduces the mypy errors from 131 to 25 errors
This commit is contained in:
Jonathan Ballet
2023-10-01 14:45:11 +02:00
committed by GitHub
parent ce4b2fe7bd
commit 56bc383dc1
21 changed files with 813 additions and 792 deletions

View File

@@ -18,6 +18,7 @@ import io
import warnings
from pydantic import validate_call, ValidationError
from typing import Dict, List, Optional, Tuple
from openapi_client.api_client import ApiClient
@@ -130,18 +131,18 @@ class AuthApi:
_params[_key] = _val
del _params['kwargs']
_collection_formats = {}
_collection_formats: Dict[str, str] = {}
# process the path parameters
_path_params = {}
_path_params: Dict[str, str] = {}
# process the query parameters
_query_params = []
_query_params: List[Tuple[str, str]] = []
# process the header parameters
_header_params = dict(_params.get('_headers', {}))
# process the form parameters
_form_params = []
_files = {}
_form_params: List[Tuple[str, str]] = []
_files: Dict[str, str] = {}
# process the body parameter
_body_params = None
# set the HTTP header `Accept`
@@ -149,9 +150,9 @@ class AuthApi:
['text/plain']) # noqa: E501
# authentication setting
_auth_settings = ['http_auth'] # noqa: E501
_auth_settings: List[str] = ['http_auth'] # noqa: E501
_response_types_map = {
_response_types_map: Dict[str, Optional[str]] = {
'200': "str",
}

View File

@@ -18,6 +18,7 @@ import io
import warnings
from pydantic import validate_call, ValidationError
from typing import Dict, List, Optional, Tuple
from pydantic import Field
from typing_extensions import Annotated
@@ -138,18 +139,18 @@ class BodyApi:
_params[_key] = _val
del _params['kwargs']
_collection_formats = {}
_collection_formats: Dict[str, str] = {}
# process the path parameters
_path_params = {}
_path_params: Dict[str, str] = {}
# process the query parameters
_query_params = []
_query_params: List[Tuple[str, str]] = []
# process the header parameters
_header_params = dict(_params.get('_headers', {}))
# process the form parameters
_form_params = []
_files = {}
_form_params: List[Tuple[str, str]] = []
_files: Dict[str, str] = {}
# process the body parameter
_body_params = None
# set the HTTP header `Accept`
@@ -157,9 +158,9 @@ class BodyApi:
['image/gif']) # noqa: E501
# authentication setting
_auth_settings = [] # noqa: E501
_auth_settings: List[str] = [] # noqa: E501
_response_types_map = {
_response_types_map: Dict[str, Optional[str]] = {
'200': "bytearray",
}
@@ -275,18 +276,18 @@ class BodyApi:
_params[_key] = _val
del _params['kwargs']
_collection_formats = {}
_collection_formats: Dict[str, str] = {}
# process the path parameters
_path_params = {}
_path_params: Dict[str, str] = {}
# process the query parameters
_query_params = []
_query_params: List[Tuple[str, str]] = []
# process the header parameters
_header_params = dict(_params.get('_headers', {}))
# process the form parameters
_form_params = []
_files = {}
_form_params: List[Tuple[str, str]] = []
_files: Dict[str, str] = {}
# process the body parameter
_body_params = None
if _params['body'] is not None:
@@ -309,9 +310,9 @@ class BodyApi:
_header_params['Content-Type'] = _content_types_list
# authentication setting
_auth_settings = [] # noqa: E501
_auth_settings: List[str] = [] # noqa: E501
_response_types_map = {
_response_types_map: Dict[str, Optional[str]] = {
'200': "str",
}
@@ -427,18 +428,18 @@ class BodyApi:
_params[_key] = _val
del _params['kwargs']
_collection_formats = {}
_collection_formats: Dict[str, str] = {}
# process the path parameters
_path_params = {}
_path_params: Dict[str, str] = {}
# process the query parameters
_query_params = []
_query_params: List[Tuple[str, str]] = []
# process the header parameters
_header_params = dict(_params.get('_headers', {}))
# process the form parameters
_form_params = []
_files = {}
_form_params: List[Tuple[str, str]] = []
_files: Dict[str, str] = {}
if _params['files'] is not None:
_files['files'] = _params['files']
_collection_formats['files'] = 'csv'
@@ -457,9 +458,9 @@ class BodyApi:
_header_params['Content-Type'] = _content_types_list
# authentication setting
_auth_settings = [] # noqa: E501
_auth_settings: List[str] = [] # noqa: E501
_response_types_map = {
_response_types_map: Dict[str, Optional[str]] = {
'200': "str",
}
@@ -575,18 +576,18 @@ class BodyApi:
_params[_key] = _val
del _params['kwargs']
_collection_formats = {}
_collection_formats: Dict[str, str] = {}
# process the path parameters
_path_params = {}
_path_params: Dict[str, str] = {}
# process the query parameters
_query_params = []
_query_params: List[Tuple[str, str]] = []
# process the header parameters
_header_params = dict(_params.get('_headers', {}))
# process the form parameters
_form_params = []
_files = {}
_form_params: List[Tuple[str, str]] = []
_files: Dict[str, str] = {}
# process the body parameter
_body_params = None
if _params['body'] is not None:
@@ -604,9 +605,9 @@ class BodyApi:
_header_params['Content-Type'] = _content_types_list
# authentication setting
_auth_settings = [] # noqa: E501
_auth_settings: List[str] = [] # noqa: E501
_response_types_map = {
_response_types_map: Dict[str, Optional[str]] = {
'200': "str",
}
@@ -722,18 +723,18 @@ class BodyApi:
_params[_key] = _val
del _params['kwargs']
_collection_formats = {}
_collection_formats: Dict[str, str] = {}
# process the path parameters
_path_params = {}
_path_params: Dict[str, str] = {}
# process the query parameters
_query_params = []
_query_params: List[Tuple[str, str]] = []
# process the header parameters
_header_params = dict(_params.get('_headers', {}))
# process the form parameters
_form_params = []
_files = {}
_form_params: List[Tuple[str, str]] = []
_files: Dict[str, str] = {}
# process the body parameter
_body_params = None
if _params['pet'] is not None:
@@ -751,9 +752,9 @@ class BodyApi:
_header_params['Content-Type'] = _content_types_list
# authentication setting
_auth_settings = [] # noqa: E501
_auth_settings: List[str] = [] # noqa: E501
_response_types_map = {
_response_types_map: Dict[str, Optional[str]] = {
'200': "Pet",
}
@@ -869,18 +870,18 @@ class BodyApi:
_params[_key] = _val
del _params['kwargs']
_collection_formats = {}
_collection_formats: Dict[str, str] = {}
# process the path parameters
_path_params = {}
_path_params: Dict[str, str] = {}
# process the query parameters
_query_params = []
_query_params: List[Tuple[str, str]] = []
# process the header parameters
_header_params = dict(_params.get('_headers', {}))
# process the form parameters
_form_params = []
_files = {}
_form_params: List[Tuple[str, str]] = []
_files: Dict[str, str] = {}
# process the body parameter
_body_params = None
if _params['pet'] is not None:
@@ -898,9 +899,9 @@ class BodyApi:
_header_params['Content-Type'] = _content_types_list
# authentication setting
_auth_settings = [] # noqa: E501
_auth_settings: List[str] = [] # noqa: E501
_response_types_map = {
_response_types_map: Dict[str, Optional[str]] = {
'200': "str",
}
@@ -1016,18 +1017,18 @@ class BodyApi:
_params[_key] = _val
del _params['kwargs']
_collection_formats = {}
_collection_formats: Dict[str, str] = {}
# process the path parameters
_path_params = {}
_path_params: Dict[str, str] = {}
# process the query parameters
_query_params = []
_query_params: List[Tuple[str, str]] = []
# process the header parameters
_header_params = dict(_params.get('_headers', {}))
# process the form parameters
_form_params = []
_files = {}
_form_params: List[Tuple[str, str]] = []
_files: Dict[str, str] = {}
# process the body parameter
_body_params = None
if _params['tag'] is not None:
@@ -1045,9 +1046,9 @@ class BodyApi:
_header_params['Content-Type'] = _content_types_list
# authentication setting
_auth_settings = [] # noqa: E501
_auth_settings: List[str] = [] # noqa: E501
_response_types_map = {
_response_types_map: Dict[str, Optional[str]] = {
'200': "str",
}

View File

@@ -18,6 +18,7 @@ import io
import warnings
from pydantic import validate_call, ValidationError
from typing import Dict, List, Optional, Tuple
from pydantic import StrictBool, StrictInt, StrictStr
@@ -149,18 +150,18 @@ class FormApi:
_params[_key] = _val
del _params['kwargs']
_collection_formats = {}
_collection_formats: Dict[str, str] = {}
# process the path parameters
_path_params = {}
_path_params: Dict[str, str] = {}
# process the query parameters
_query_params = []
_query_params: List[Tuple[str, str]] = []
# process the header parameters
_header_params = dict(_params.get('_headers', {}))
# process the form parameters
_form_params = []
_files = {}
_form_params: List[Tuple[str, str]] = []
_files: Dict[str, str] = {}
if _params['integer_form'] is not None:
_form_params.append(('integer_form', _params['integer_form']))
@@ -184,9 +185,9 @@ class FormApi:
_header_params['Content-Type'] = _content_types_list
# authentication setting
_auth_settings = [] # noqa: E501
_auth_settings: List[str] = [] # noqa: E501
_response_types_map = {
_response_types_map: Dict[str, Optional[str]] = {
'200': "str",
}
@@ -327,18 +328,18 @@ class FormApi:
_params[_key] = _val
del _params['kwargs']
_collection_formats = {}
_collection_formats: Dict[str, str] = {}
# process the path parameters
_path_params = {}
_path_params: Dict[str, str] = {}
# process the query parameters
_query_params = []
_query_params: List[Tuple[str, str]] = []
# process the header parameters
_header_params = dict(_params.get('_headers', {}))
# process the form parameters
_form_params = []
_files = {}
_form_params: List[Tuple[str, str]] = []
_files: Dict[str, str] = {}
if _params['form1'] is not None:
_form_params.append(('form1', _params['form1']))
@@ -371,9 +372,9 @@ class FormApi:
_header_params['Content-Type'] = _content_types_list
# authentication setting
_auth_settings = [] # noqa: E501
_auth_settings: List[str] = [] # noqa: E501
_response_types_map = {
_response_types_map: Dict[str, Optional[str]] = {
'200': "str",
}

View File

@@ -18,6 +18,7 @@ import io
import warnings
from pydantic import validate_call, ValidationError
from typing import Dict, List, Optional, Tuple
from pydantic import StrictBool, StrictInt, StrictStr
@@ -149,13 +150,13 @@ class HeaderApi:
_params[_key] = _val
del _params['kwargs']
_collection_formats = {}
_collection_formats: Dict[str, str] = {}
# process the path parameters
_path_params = {}
_path_params: Dict[str, str] = {}
# process the query parameters
_query_params = []
_query_params: List[Tuple[str, str]] = []
# process the header parameters
_header_params = dict(_params.get('_headers', {}))
if _params['integer_header'] is not None:
@@ -168,8 +169,8 @@ class HeaderApi:
_header_params['string_header'] = _params['string_header']
# process the form parameters
_form_params = []
_files = {}
_form_params: List[Tuple[str, str]] = []
_files: Dict[str, str] = {}
# process the body parameter
_body_params = None
# set the HTTP header `Accept`
@@ -177,9 +178,9 @@ class HeaderApi:
['text/plain']) # noqa: E501
# authentication setting
_auth_settings = [] # noqa: E501
_auth_settings: List[str] = [] # noqa: E501
_response_types_map = {
_response_types_map: Dict[str, Optional[str]] = {
'200': "str",
}

View File

@@ -18,6 +18,7 @@ import io
import warnings
from pydantic import validate_call, ValidationError
from typing import Dict, List, Optional, Tuple
from pydantic import StrictInt, StrictStr
@@ -142,10 +143,10 @@ class PathApi:
_params[_key] = _val
del _params['kwargs']
_collection_formats = {}
_collection_formats: Dict[str, str] = {}
# process the path parameters
_path_params = {}
_path_params: Dict[str, str] = {}
if _params['path_string'] is not None:
_path_params['path_string'] = _params['path_string']
@@ -154,12 +155,12 @@ class PathApi:
# process the query parameters
_query_params = []
_query_params: List[Tuple[str, str]] = []
# process the header parameters
_header_params = dict(_params.get('_headers', {}))
# process the form parameters
_form_params = []
_files = {}
_form_params: List[Tuple[str, str]] = []
_files: Dict[str, str] = {}
# process the body parameter
_body_params = None
# set the HTTP header `Accept`
@@ -167,9 +168,9 @@ class PathApi:
['text/plain']) # noqa: E501
# authentication setting
_auth_settings = [] # noqa: E501
_auth_settings: List[str] = [] # noqa: E501
_response_types_map = {
_response_types_map: Dict[str, Optional[str]] = {
'200': "str",
}

View File

@@ -18,6 +18,7 @@ import io
import warnings
from pydantic import validate_call, ValidationError
from typing import Dict, List, Optional, Tuple
from datetime import date, datetime
@@ -144,21 +145,21 @@ class QueryApi:
_params[_key] = _val
del _params['kwargs']
_collection_formats = {}
_collection_formats: Dict[str, str] = {}
# process the path parameters
_path_params = {}
_path_params: Dict[str, str] = {}
# process the query parameters
_query_params = []
_query_params: List[Tuple[str, str]] = []
if _params.get('enum_ref_string_query') is not None: # noqa: E501
_query_params.append(('enum_ref_string_query', _params['enum_ref_string_query'].value))
# process the header parameters
_header_params = dict(_params.get('_headers', {}))
# process the form parameters
_form_params = []
_files = {}
_form_params: List[Tuple[str, str]] = []
_files: Dict[str, str] = {}
# process the body parameter
_body_params = None
# set the HTTP header `Accept`
@@ -166,9 +167,9 @@ class QueryApi:
['text/plain']) # noqa: E501
# authentication setting
_auth_settings = [] # noqa: E501
_auth_settings: List[str] = [] # noqa: E501
_response_types_map = {
_response_types_map: Dict[str, Optional[str]] = {
'200': "str",
}
@@ -294,13 +295,13 @@ class QueryApi:
_params[_key] = _val
del _params['kwargs']
_collection_formats = {}
_collection_formats: Dict[str, str] = {}
# process the path parameters
_path_params = {}
_path_params: Dict[str, str] = {}
# process the query parameters
_query_params = []
_query_params: List[Tuple[str, str]] = []
if _params.get('datetime_query') is not None: # noqa: E501
if isinstance(_params['datetime_query'], datetime):
_query_params.append(('datetime_query', _params['datetime_query'].strftime(self.api_client.configuration.datetime_format)))
@@ -319,8 +320,8 @@ class QueryApi:
# process the header parameters
_header_params = dict(_params.get('_headers', {}))
# process the form parameters
_form_params = []
_files = {}
_form_params: List[Tuple[str, str]] = []
_files: Dict[str, str] = {}
# process the body parameter
_body_params = None
# set the HTTP header `Accept`
@@ -328,9 +329,9 @@ class QueryApi:
['text/plain']) # noqa: E501
# authentication setting
_auth_settings = [] # noqa: E501
_auth_settings: List[str] = [] # noqa: E501
_response_types_map = {
_response_types_map: Dict[str, Optional[str]] = {
'200': "str",
}
@@ -456,13 +457,13 @@ class QueryApi:
_params[_key] = _val
del _params['kwargs']
_collection_formats = {}
_collection_formats: Dict[str, str] = {}
# process the path parameters
_path_params = {}
_path_params: Dict[str, str] = {}
# process the query parameters
_query_params = []
_query_params: List[Tuple[str, str]] = []
if _params.get('integer_query') is not None: # noqa: E501
_query_params.append(('integer_query', _params['integer_query']))
@@ -475,8 +476,8 @@ class QueryApi:
# process the header parameters
_header_params = dict(_params.get('_headers', {}))
# process the form parameters
_form_params = []
_files = {}
_form_params: List[Tuple[str, str]] = []
_files: Dict[str, str] = {}
# process the body parameter
_body_params = None
# set the HTTP header `Accept`
@@ -484,9 +485,9 @@ class QueryApi:
['text/plain']) # noqa: E501
# authentication setting
_auth_settings = [] # noqa: E501
_auth_settings: List[str] = [] # noqa: E501
_response_types_map = {
_response_types_map: Dict[str, Optional[str]] = {
'200': "str",
}
@@ -602,21 +603,21 @@ class QueryApi:
_params[_key] = _val
del _params['kwargs']
_collection_formats = {}
_collection_formats: Dict[str, str] = {}
# process the path parameters
_path_params = {}
_path_params: Dict[str, str] = {}
# process the query parameters
_query_params = []
_query_params: List[Tuple[str, str]] = []
if _params.get('query_object') is not None: # noqa: E501
_query_params.append(('query_object', _params['query_object']))
# process the header parameters
_header_params = dict(_params.get('_headers', {}))
# process the form parameters
_form_params = []
_files = {}
_form_params: List[Tuple[str, str]] = []
_files: Dict[str, str] = {}
# process the body parameter
_body_params = None
# set the HTTP header `Accept`
@@ -624,9 +625,9 @@ class QueryApi:
['text/plain']) # noqa: E501
# authentication setting
_auth_settings = [] # noqa: E501
_auth_settings: List[str] = [] # noqa: E501
_response_types_map = {
_response_types_map: Dict[str, Optional[str]] = {
'200': "str",
}
@@ -742,21 +743,21 @@ class QueryApi:
_params[_key] = _val
del _params['kwargs']
_collection_formats = {}
_collection_formats: Dict[str, str] = {}
# process the path parameters
_path_params = {}
_path_params: Dict[str, str] = {}
# process the query parameters
_query_params = []
_query_params: List[Tuple[str, str]] = []
if _params.get('query_object') is not None: # noqa: E501
_query_params.append(('query_object', _params['query_object']))
# process the header parameters
_header_params = dict(_params.get('_headers', {}))
# process the form parameters
_form_params = []
_files = {}
_form_params: List[Tuple[str, str]] = []
_files: Dict[str, str] = {}
# process the body parameter
_body_params = None
# set the HTTP header `Accept`
@@ -764,9 +765,9 @@ class QueryApi:
['text/plain']) # noqa: E501
# authentication setting
_auth_settings = [] # noqa: E501
_auth_settings: List[str] = [] # noqa: E501
_response_types_map = {
_response_types_map: Dict[str, Optional[str]] = {
'200': "str",
}
@@ -882,21 +883,21 @@ class QueryApi:
_params[_key] = _val
del _params['kwargs']
_collection_formats = {}
_collection_formats: Dict[str, str] = {}
# process the path parameters
_path_params = {}
_path_params: Dict[str, str] = {}
# process the query parameters
_query_params = []
_query_params: List[Tuple[str, str]] = []
if _params.get('query_object') is not None: # noqa: E501
_query_params.append(('query_object', _params['query_object']))
# process the header parameters
_header_params = dict(_params.get('_headers', {}))
# process the form parameters
_form_params = []
_files = {}
_form_params: List[Tuple[str, str]] = []
_files: Dict[str, str] = {}
# process the body parameter
_body_params = None
# set the HTTP header `Accept`
@@ -904,9 +905,9 @@ class QueryApi:
['text/plain']) # noqa: E501
# authentication setting
_auth_settings = [] # noqa: E501
_auth_settings: List[str] = [] # noqa: E501
_response_types_map = {
_response_types_map: Dict[str, Optional[str]] = {
'200': "str",
}
@@ -1022,21 +1023,21 @@ class QueryApi:
_params[_key] = _val
del _params['kwargs']
_collection_formats = {}
_collection_formats: Dict[str, str] = {}
# process the path parameters
_path_params = {}
_path_params: Dict[str, str] = {}
# process the query parameters
_query_params = []
_query_params: List[Tuple[str, str]] = []
if _params.get('query_object') is not None: # noqa: E501
_query_params.append(('query_object', _params['query_object']))
# process the header parameters
_header_params = dict(_params.get('_headers', {}))
# process the form parameters
_form_params = []
_files = {}
_form_params: List[Tuple[str, str]] = []
_files: Dict[str, str] = {}
# process the body parameter
_body_params = None
# set the HTTP header `Accept`
@@ -1044,9 +1045,9 @@ class QueryApi:
['text/plain']) # noqa: E501
# authentication setting
_auth_settings = [] # noqa: E501
_auth_settings: List[str] = [] # noqa: E501
_response_types_map = {
_response_types_map: Dict[str, Optional[str]] = {
'200': "str",
}
@@ -1162,21 +1163,21 @@ class QueryApi:
_params[_key] = _val
del _params['kwargs']
_collection_formats = {}
_collection_formats: Dict[str, str] = {}
# process the path parameters
_path_params = {}
_path_params: Dict[str, str] = {}
# process the query parameters
_query_params = []
_query_params: List[Tuple[str, str]] = []
if _params.get('query_object') is not None: # noqa: E501
_query_params.append(('query_object', _params['query_object']))
# process the header parameters
_header_params = dict(_params.get('_headers', {}))
# process the form parameters
_form_params = []
_files = {}
_form_params: List[Tuple[str, str]] = []
_files: Dict[str, str] = {}
# process the body parameter
_body_params = None
# set the HTTP header `Accept`
@@ -1184,9 +1185,9 @@ class QueryApi:
['text/plain']) # noqa: E501
# authentication setting
_auth_settings = [] # noqa: E501
_auth_settings: List[str] = [] # noqa: E501
_response_types_map = {
_response_types_map: Dict[str, Optional[str]] = {
'200': "str",
}