python: enable more mypy checks 1/n (#17556)

* python: more mypy checks

* mypy: check_untyped_defs

* mypy: disallow_subclassing_any

* mypy: disallow_untyped_decorators

* mypy: disallow_any_generics
This commit is contained in:
Jonathan Ballet 2024-01-09 09:45:05 +01:00 committed by GitHub
parent c041d7e12f
commit df7976c1a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
234 changed files with 992 additions and 628 deletions

View File

@ -10,7 +10,7 @@ from typing_extensions import Annotated
{{import}}
{{/imports}}
from {{packageName}}.api_client import ApiClient
from {{packageName}}.api_client import ApiClient, RequestSerialized
from {{packageName}}.api_response import ApiResponse
from {{packageName}}.rest import RESTResponseType
@ -77,7 +77,7 @@ class {{classname}}:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
{{#servers.0}}
_hosts = [{{#servers}}

View File

@ -11,13 +11,13 @@ import re
import tempfile
from urllib.parse import quote
from typing import Tuple, Optional, List
from typing import Tuple, Optional, List, Dict
{{#tornado}}
import tornado.gen
{{/tornado}}
from {{packageName}}.configuration import Configuration
from {{packageName}}.api_response import ApiResponse
from {{packageName}}.api_response import ApiResponse, T as ApiResponseT
import {{modelPackage}}
from {{packageName}} import rest
from {{packageName}}.exceptions import (
@ -30,6 +30,7 @@ from {{packageName}}.exceptions import (
ServiceException
)
RequestSerialized = Tuple[str, str, Dict[str, str], Optional[str], List[str]]
class ApiClient:
"""Generic API client for OpenAPI client library builds.
@ -151,7 +152,7 @@ class ApiClient:
collection_formats=None,
_host=None,
_request_auth=None
) -> Tuple:
) -> RequestSerialized:
"""Builds the HTTP request params needed by the request.
:param method: Method to call.
@ -287,8 +288,8 @@ class ApiClient:
def response_deserialize(
self,
response_data: rest.RESTResponse,
response_types_map=None
) -> ApiResponse:
response_types_map: Optional[Dict[str, ApiResponseT]]=None
) -> ApiResponse[ApiResponseT]:
"""Deserializes response into an object.
:param response_data: RESTResponse object to be deserialized.
:param response_types_map: dict of response types.
@ -409,12 +410,16 @@ class ApiClient:
if isinstance(klass, str):
if klass.startswith('List['):
sub_kls = re.match(r'List\[(.*)]', klass).group(1)
m = re.match(r'List\[(.*)]', klass)
assert m is not None, "Malformed List type definition"
sub_kls = m.group(1)
return [self.__deserialize(sub_data, sub_kls)
for sub_data in data]
if klass.startswith('Dict['):
sub_kls = re.match(r'Dict\[([^,]*), (.*)]', klass).group(2)
m = re.match(r'Dict\[([^,]*), (.*)]', klass)
assert m is not None, "Malformed Dict type definition"
sub_kls = m.group(2)
return {k: self.__deserialize(v, sub_kls)
for k, v in data.items()}
@ -442,7 +447,7 @@ class ApiClient:
:param dict collection_formats: Parameter collection formats
:return: Parameters as list of tuples, collections formatted
"""
new_params = []
new_params: List[Tuple[str, str]] = []
if collection_formats is None:
collection_formats = {}
for k, v in params.items() if isinstance(params, dict) else params:
@ -472,7 +477,7 @@ class ApiClient:
:param dict collection_formats: Parameter collection formats
:return: URL query string (e.g. a=Hello%20World&b=123)
"""
new_params = []
new_params: List[Tuple[str, str]] = []
if collection_formats is None:
collection_formats = {}
for k, v in params.items() if isinstance(params, dict) else params:
@ -666,10 +671,12 @@ class ApiClient:
content_disposition = response.getheader("Content-Disposition")
if content_disposition:
filename = re.search(
m = re.search(
r'filename=[\'"]?([^\'"\s]+)[\'"]?',
content_disposition
).group(1)
)
assert m is not None, "Unexpected 'content-disposition' header value"
filename = m.group(1)
path = os.path.join(os.path.dirname(path), filename)
with open(path, "wb") as f:

View File

@ -6,7 +6,7 @@ import io
import json
import re
import ssl
from typing import Optional
from typing import Optional, Union
import aiohttp
import aiohttp_retry
@ -189,6 +189,7 @@ class RESTClientObject:
declared content type."""
raise ApiException(status=0, reason=msg)
pool_manager: Union[aiohttp.ClientSession, aiohttp_retry.RetryClient]
if self.retry_client is not None and method in ALLOW_RETRY_METHODS:
pool_manager = self.retry_client
else:

View File

@ -4,10 +4,12 @@
import copy
import logging
from logging import FileHandler
{{^asyncio}}
import multiprocessing
{{/asyncio}}
import sys
from typing import Optional
import urllib3
import http.client as httplib
@ -204,7 +206,7 @@ conf = {{{packageName}}}.Configuration(
self.logger_stream_handler = None
"""Log stream handler
"""
self.logger_file_handler = None
self.logger_file_handler: Optional[FileHandler] = None
"""Log file handler
"""
self.logger_file = None
@ -252,7 +254,7 @@ conf = {{{packageName}}}.Configuration(
"""
{{/asyncio}}
self.proxy = None
self.proxy: Optional[str] = None
"""Proxy URL
"""
self.proxy_headers = None

View File

@ -95,7 +95,7 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}
return v
@classmethod
def from_dict(cls, obj: dict) -> Self:
def from_dict(cls, obj: Dict[str, Any]) -> Self:
return cls.from_json(json.dumps(obj))
@classmethod
@ -159,7 +159,7 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}
else:
return json.dumps(self.actual_instance)
def to_dict(self) -> Optional[Union[Dict, {{#anyOf}}{{.}}{{^-last}}, {{/-last}}{{/anyOf}}]]:
def to_dict(self) -> Optional[Union[Dict[str, Any], {{#anyOf}}{{.}}{{^-last}}, {{/-last}}{{/anyOf}}]]:
"""Returns the dict representation of the actual instance"""
if self.actual_instance is None:
return None

View File

@ -93,7 +93,7 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}
}
@classmethod
def get_discriminator_value(cls, obj: Dict) -> Optional[str]:
def get_discriminator_value(cls, obj: Dict[str, Any]) -> Optional[str]:
"""Returns the discriminator value (object type) of the data"""
discriminator_value = obj[cls.__discriminator_property_name]
if discriminator_value:
@ -236,7 +236,7 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}
{{#hasChildren}}
@classmethod
def from_dict(cls, obj: Dict) -> Optional[{{#discriminator}}Union[{{#children}}Self{{^-last}}, {{/-last}}{{/children}}]{{/discriminator}}{{^discriminator}}Self{{/discriminator}}]:
def from_dict(cls, obj: Dict[str, Any]) -> Optional[{{#discriminator}}Union[{{#children}}Self{{^-last}}, {{/-last}}{{/children}}]{{/discriminator}}{{^discriminator}}Self{{/discriminator}}]:
"""Create an instance of {{{classname}}} from a dict"""
{{#discriminator}}
# look up the object type based on discriminator mapping
@ -252,7 +252,7 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}
{{/hasChildren}}
{{^hasChildren}}
@classmethod
def from_dict(cls, obj: Optional[Dict]) -> Optional[Self]:
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of {{{classname}}} from a dict"""
if obj is None:
return None

View File

@ -93,11 +93,16 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}
return v
@classmethod
def from_dict(cls, obj: dict) -> Self:
def from_dict(cls, obj: Union[str, Dict[str, Any]]) -> Self:
return cls.from_json(json.dumps(obj))
@classmethod
{{#isNullable}}
def from_json(cls, json_str: Optional[str]) -> Self:
{{/isNullable}}
{{^isNullable}}
def from_json(cls, json_str: str) -> Self:
{{/isNullable}}
"""Returns the object represented by the json string"""
instance = cls.model_construct()
{{#isNullable}}
@ -180,7 +185,7 @@ class {{classname}}({{#parent}}{{{.}}}{{/parent}}{{^parent}}BaseModel{{/parent}}
else:
return json.dumps(self.actual_instance)
def to_dict(self) -> Optional[Union[Dict, {{#oneOf}}{{{.}}}{{^-last}}, {{/-last}}{{/oneOf}}]]:
def to_dict(self) -> Optional[Union[Dict[str, Any], {{#oneOf}}{{{.}}}{{^-last}}, {{/-last}}{{/oneOf}}]]:
"""Returns the dict representation of the actual instance"""
if self.actual_instance is None:
return None

View File

@ -49,3 +49,34 @@ files = [
#"test", # auto-generated tests
"tests", # hand-written tests
]
# TODO: enable "strict" once all these individual checks are passing
# strict = true
# List from: https://mypy.readthedocs.io/en/stable/existing_code.html#introduce-stricter-options
warn_unused_configs = true
warn_redundant_casts = true
warn_unused_ignores = true
## Getting these passing should be easy
strict_equality = true
strict_concatenate = true
## Strongly recommend enabling this one as soon as you can
check_untyped_defs = true
## These shouldn't be too much additional work, but may be tricky to
## get passing if you use a lot of untyped libraries
disallow_subclassing_any = true
disallow_untyped_decorators = true
disallow_any_generics = true
### These next few are various gradations of forcing use of type annotations
#disallow_untyped_calls = true
#disallow_incomplete_defs = true
#disallow_untyped_defs = true
#
### This one isn't too hard to get passing, but return on investment is lower
#no_implicit_reexport = true
#
### This one can be tricky to get passing if you use a lot of untyped libraries
#warn_return_any = true

View File

@ -202,14 +202,13 @@ class RESTClientObject:
preload_content=False
)
# Pass a `string` parameter directly in the body to support
# other content types than Json when `body` argument is
# provided in serialized form
# other content types than JSON when `body` argument is
# provided in serialized form.
elif isinstance(body, str) or isinstance(body, bytes):
request_body = body
r = self.pool_manager.request(
method,
url,
body=request_body,
body=body,
timeout=timeout,
headers=headers,
preload_content=False

View File

@ -3,12 +3,16 @@
from base64 import b64encode
from Crypto.IO import PEM, PKCS8
from Crypto.Hash import SHA256, SHA512
from Crypto.Hash.SHA512 import SHA512Hash
from Crypto.Hash.SHA256 import SHA256Hash
from Crypto.PublicKey import RSA, ECC
from Crypto.Signature import PKCS1_v1_5, pss, DSS
from datetime import timedelta
from email.utils import formatdate
import os
import re
from time import time
from typing import List, Optional, Union
from urllib.parse import urlencode, urlparse
# The constants below define a subset of HTTP headers that can be included in the
@ -57,18 +61,20 @@ HASH_SHA512 = 'sha512'
class HttpSigningConfiguration:
"""The configuration parameters for the HTTP signature security scheme.
The HTTP signature security scheme is used to sign HTTP requests with a private key
which is in possession of the API client.
An 'Authorization' header is calculated by creating a hash of select headers,
An ``Authorization`` header is calculated by creating a hash of select headers,
and optionally the body of the HTTP request, then signing the hash value using
a private key. The 'Authorization' header is added to outbound HTTP requests.
a private key. The ``Authorization`` header is added to outbound HTTP requests.
:param key_id: A string value specifying the identifier of the cryptographic key,
when signing HTTP requests.
:param signing_scheme: A string value specifying the signature scheme, when
signing HTTP requests.
Supported value are hs2019, rsa-sha256, rsa-sha512.
Avoid using rsa-sha256, rsa-sha512 as they are deprecated. These values are
Supported value are: ``hs2019``, ``rsa-sha256``, ``rsa-sha512``.
Avoid using ``rsa-sha256``, ``rsa-sha512`` as they are deprecated. These values are
available for server-side applications that only support the older
HTTP signature algorithms.
:param private_key_path: A string value specifying the path of the file containing
@ -77,18 +83,19 @@ class HttpSigningConfiguration:
the private key.
:param signed_headers: A list of strings. Each value is the name of a HTTP header
that must be included in the HTTP signature calculation.
The two special signature headers '(request-target)' and '(created)' SHOULD be
The two special signature headers ``(request-target)`` and ``(created)`` SHOULD be
included in SignedHeaders.
The '(created)' header expresses when the signature was created.
The '(request-target)' header is a concatenation of the lowercased :method, an
The ``(created)`` header expresses when the signature was created.
The ``(request-target)`` header is a concatenation of the lowercased :method, an
ASCII space, and the :path pseudo-headers.
When signed_headers is not specified, the client defaults to a single value,
'(created)', in the list of HTTP headers.
``(created)``, in the list of HTTP headers.
When SignedHeaders contains the 'Digest' value, the client performs the
following operations:
1. Calculate a digest of request body, as specified in RFC3230, section 4.3.2.
2. Set the 'Digest' header in the request body.
3. Include the 'Digest' header and value in the HTTP signature.
1. Calculate a digest of request body, as specified in `RFC3230,
section 4.3.2<https://datatracker.ietf.org/doc/html/rfc3230#section-4.3.2>`_.
2. Set the ``Digest`` header in the request body.
3. Include the ``Digest`` header and value in the HTTP signature.
:param signing_algorithm: A string value specifying the signature algorithm, when
signing HTTP requests.
Supported values are:
@ -106,12 +113,16 @@ class HttpSigningConfiguration:
:param signature_max_validity: The signature max validity, expressed as
a datetime.timedelta value. It must be a positive value.
"""
def __init__(self, key_id, signing_scheme, private_key_path,
private_key_passphrase=None,
signed_headers=None,
signing_algorithm=None,
hash_algorithm=None,
signature_max_validity=None) -> None:
def __init__(self,
key_id: str,
signing_scheme: str,
private_key_path: str,
private_key_passphrase: Union[None, str]=None,
signed_headers: Optional[List[str]]=None,
signing_algorithm: Optional[str]=None,
hash_algorithm: Optional[str]=None,
signature_max_validity: Optional[timedelta]=None,
) -> None:
self.key_id = key_id
if signing_scheme not in {SCHEME_HS2019, SCHEME_RSA_SHA256, SCHEME_RSA_SHA512}:
raise Exception("Unsupported security scheme: {0}".format(signing_scheme))
@ -155,11 +166,11 @@ class HttpSigningConfiguration:
if HEADER_AUTHORIZATION in signed_headers:
raise Exception("'Authorization' header cannot be included in signed headers")
self.signed_headers = signed_headers
self.private_key = None
self.private_key: Optional[Union[ECC.EccKey, RSA.RsaKey]] = None
"""The private key used to sign HTTP requests.
Initialized when the PEM-encoded private key is loaded from a file.
"""
self.host = None
self.host: Optional[str] = None
"""The host name, optionally followed by a colon and TCP port number.
"""
self._load_private_key()
@ -197,7 +208,7 @@ class HttpSigningConfiguration:
def get_public_key(self):
"""Returns the public key object associated with the private key.
"""
pubkey = None
pubkey: Optional[Union[ECC.EccKey, RSA.RsaKey]] = None
if isinstance(self.private_key, RSA.RsaKey):
pubkey = self.private_key.publickey()
elif isinstance(self.private_key, ECC.EccKey):
@ -226,8 +237,11 @@ class HttpSigningConfiguration:
elif pem_header in {'PRIVATE KEY', 'ENCRYPTED PRIVATE KEY'}:
# Key is in PKCS8 format, which is capable of holding many different
# types of private keys, not just EC keys.
(key_binary, pem_header, is_encrypted) = \
PEM.decode(pem_data, self.private_key_passphrase)
if self.private_key_passphrase is not None:
passphrase = self.private_key_passphrase.encode("utf-8")
else:
passphrase = None
(key_binary, pem_header, is_encrypted) = PEM.decode(pem_data, passphrase)
(oid, privkey, params) = \
PKCS8.unwrap(key_binary, passphrase=self.private_key_passphrase)
if oid == '1.2.840.10045.2.1':
@ -308,8 +322,11 @@ class HttpSigningConfiguration:
request_headers_dict[HEADER_DIGEST] = '{0}{1}'.format(
digest_prefix, b64_body_digest.decode('ascii'))
elif hdr_key == HEADER_HOST.lower():
value = target_host
request_headers_dict[HEADER_HOST] = '{0}'.format(target_host)
if isinstance(target_host, bytes):
value = target_host.decode('ascii')
else:
value = target_host
request_headers_dict[HEADER_HOST] = value
else:
value = next((v for k, v in headers.items() if k.lower() == hdr_key), None)
if value is None:
@ -330,6 +347,9 @@ class HttpSigningConfiguration:
The prefix is a string that identifies the cryptographic hash. It is used
to generate the 'Digest' header as specified in RFC 3230.
"""
digest: Union[SHA256Hash, SHA512Hash]
if self.hash_algorithm == HASH_SHA512:
digest = SHA512.new()
prefix = 'SHA-512='

View File

@ -18,7 +18,7 @@ from typing import Any, Dict, List, Optional, Tuple, Union
from typing_extensions import Annotated
from openapi_client.api_client import ApiClient
from openapi_client.api_client import ApiClient, RequestSerialized
from openapi_client.api_response import ApiResponse
from openapi_client.rest import RESTResponseType
@ -227,7 +227,7 @@ class AuthApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -470,7 +470,7 @@ class AuthApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None

View File

@ -23,7 +23,7 @@ from typing_extensions import Annotated
from openapi_client.models.pet import Pet
from openapi_client.models.tag import Tag
from openapi_client.api_client import ApiClient
from openapi_client.api_client import ApiClient, RequestSerialized
from openapi_client.api_response import ApiResponse
from openapi_client.rest import RESTResponseType
@ -232,7 +232,7 @@ class BodyApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -487,7 +487,7 @@ class BodyApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -762,7 +762,7 @@ class BodyApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -1033,7 +1033,7 @@ class BodyApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -1303,7 +1303,7 @@ class BodyApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -1573,7 +1573,7 @@ class BodyApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -1843,7 +1843,7 @@ class BodyApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -2113,7 +2113,7 @@ class BodyApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -2383,7 +2383,7 @@ class BodyApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None

View File

@ -20,7 +20,7 @@ from typing_extensions import Annotated
from pydantic import StrictBool, StrictInt, StrictStr
from typing import Optional
from openapi_client.api_client import ApiClient
from openapi_client.api_client import ApiClient, RequestSerialized
from openapi_client.api_response import ApiResponse
from openapi_client.rest import RESTResponseType
@ -268,7 +268,7 @@ class FormApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -607,7 +607,7 @@ class FormApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None

View File

@ -21,7 +21,7 @@ from pydantic import StrictBool, StrictInt, StrictStr, field_validator
from typing import Optional
from openapi_client.models.string_enum_ref import StringEnumRef
from openapi_client.api_client import ApiClient
from openapi_client.api_client import ApiClient, RequestSerialized
from openapi_client.api_response import ApiResponse
from openapi_client.rest import RESTResponseType
@ -295,7 +295,7 @@ class HeaderApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None

View File

@ -20,7 +20,7 @@ from typing_extensions import Annotated
from pydantic import StrictInt, StrictStr, field_validator
from openapi_client.models.string_enum_ref import StringEnumRef
from openapi_client.api_client import ApiClient
from openapi_client.api_client import ApiClient, RequestSerialized
from openapi_client.api_response import ApiResponse
from openapi_client.rest import RESTResponseType
@ -281,7 +281,7 @@ class PathApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None

View File

@ -24,7 +24,7 @@ from openapi_client.models.pet import Pet
from openapi_client.models.string_enum_ref import StringEnumRef
from openapi_client.models.test_query_style_form_explode_true_array_string_query_object_parameter import TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter
from openapi_client.api_client import ApiClient
from openapi_client.api_client import ApiClient, RequestSerialized
from openapi_client.api_response import ApiResponse
from openapi_client.rest import RESTResponseType
@ -259,7 +259,7 @@ class QueryApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -548,7 +548,7 @@ class QueryApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -859,7 +859,7 @@ class QueryApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -1126,7 +1126,7 @@ class QueryApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -1385,7 +1385,7 @@ class QueryApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -1644,7 +1644,7 @@ class QueryApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -1903,7 +1903,7 @@ class QueryApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -2162,7 +2162,7 @@ class QueryApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None

View File

@ -22,10 +22,10 @@ import re
import tempfile
from urllib.parse import quote
from typing import Tuple, Optional, List
from typing import Tuple, Optional, List, Dict
from openapi_client.configuration import Configuration
from openapi_client.api_response import ApiResponse
from openapi_client.api_response import ApiResponse, T as ApiResponseT
import openapi_client.models
from openapi_client import rest
from openapi_client.exceptions import (
@ -38,6 +38,7 @@ from openapi_client.exceptions import (
ServiceException
)
RequestSerialized = Tuple[str, str, Dict[str, str], Optional[str], List[str]]
class ApiClient:
"""Generic API client for OpenAPI client library builds.
@ -147,7 +148,7 @@ class ApiClient:
collection_formats=None,
_host=None,
_request_auth=None
) -> Tuple:
) -> RequestSerialized:
"""Builds the HTTP request params needed by the request.
:param method: Method to call.
@ -280,8 +281,8 @@ class ApiClient:
def response_deserialize(
self,
response_data: rest.RESTResponse,
response_types_map=None
) -> ApiResponse:
response_types_map: Optional[Dict[str, ApiResponseT]]=None
) -> ApiResponse[ApiResponseT]:
"""Deserializes response into an object.
:param response_data: RESTResponse object to be deserialized.
:param response_types_map: dict of response types.
@ -402,12 +403,16 @@ class ApiClient:
if isinstance(klass, str):
if klass.startswith('List['):
sub_kls = re.match(r'List\[(.*)]', klass).group(1)
m = re.match(r'List\[(.*)]', klass)
assert m is not None, "Malformed List type definition"
sub_kls = m.group(1)
return [self.__deserialize(sub_data, sub_kls)
for sub_data in data]
if klass.startswith('Dict['):
sub_kls = re.match(r'Dict\[([^,]*), (.*)]', klass).group(2)
m = re.match(r'Dict\[([^,]*), (.*)]', klass)
assert m is not None, "Malformed Dict type definition"
sub_kls = m.group(2)
return {k: self.__deserialize(v, sub_kls)
for k, v in data.items()}
@ -435,7 +440,7 @@ class ApiClient:
:param dict collection_formats: Parameter collection formats
:return: Parameters as list of tuples, collections formatted
"""
new_params = []
new_params: List[Tuple[str, str]] = []
if collection_formats is None:
collection_formats = {}
for k, v in params.items() if isinstance(params, dict) else params:
@ -465,7 +470,7 @@ class ApiClient:
:param dict collection_formats: Parameter collection formats
:return: URL query string (e.g. a=Hello%20World&b=123)
"""
new_params = []
new_params: List[Tuple[str, str]] = []
if collection_formats is None:
collection_formats = {}
for k, v in params.items() if isinstance(params, dict) else params:
@ -650,10 +655,12 @@ class ApiClient:
content_disposition = response.getheader("Content-Disposition")
if content_disposition:
filename = re.search(
m = re.search(
r'filename=[\'"]?([^\'"\s]+)[\'"]?',
content_disposition
).group(1)
)
assert m is not None, "Unexpected 'content-disposition' header value"
filename = m.group(1)
path = os.path.join(os.path.dirname(path), filename)
with open(path, "wb") as f:

View File

@ -15,8 +15,10 @@
import copy
import logging
from logging import FileHandler
import multiprocessing
import sys
from typing import Optional
import urllib3
import http.client as httplib
@ -133,7 +135,7 @@ conf = openapi_client.Configuration(
self.logger_stream_handler = None
"""Log stream handler
"""
self.logger_file_handler = None
self.logger_file_handler: Optional[FileHandler] = None
"""Log file handler
"""
self.logger_file = None
@ -173,7 +175,7 @@ conf = openapi_client.Configuration(
cpu_count * 5 is used as default value to increase performance.
"""
self.proxy = None
self.proxy: Optional[str] = None
"""Proxy URL
"""
self.proxy_headers = None

View File

@ -73,7 +73,7 @@ class Bird(BaseModel):
return _dict
@classmethod
def from_dict(cls, obj: Optional[Dict]) -> Optional[Self]:
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of Bird from a dict"""
if obj is None:
return None

View File

@ -73,7 +73,7 @@ class Category(BaseModel):
return _dict
@classmethod
def from_dict(cls, obj: Optional[Dict]) -> Optional[Self]:
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of Category from a dict"""
if obj is None:
return None

View File

@ -76,7 +76,7 @@ class DataQuery(Query):
return _dict
@classmethod
def from_dict(cls, obj: Optional[Dict]) -> Optional[Self]:
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of DataQuery from a dict"""
if obj is None:
return None

View File

@ -106,7 +106,7 @@ class DefaultValue(BaseModel):
return _dict
@classmethod
def from_dict(cls, obj: Optional[Dict]) -> Optional[Self]:
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of DefaultValue from a dict"""
if obj is None:
return None

View File

@ -75,7 +75,7 @@ class NumberPropertiesOnly(BaseModel):
return _dict
@classmethod
def from_dict(cls, obj: Optional[Dict]) -> Optional[Self]:
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of NumberPropertiesOnly from a dict"""
if obj is None:
return None

View File

@ -99,7 +99,7 @@ class Pet(BaseModel):
return _dict
@classmethod
def from_dict(cls, obj: Optional[Dict]) -> Optional[Self]:
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of Pet from a dict"""
if obj is None:
return None

View File

@ -84,7 +84,7 @@ class Query(BaseModel):
return _dict
@classmethod
def from_dict(cls, obj: Dict) -> Optional[Self]:
def from_dict(cls, obj: Dict[str, Any]) -> Optional[Self]:
"""Create an instance of Query from a dict"""

View File

@ -73,7 +73,7 @@ class Tag(BaseModel):
return _dict
@classmethod
def from_dict(cls, obj: Optional[Dict]) -> Optional[Self]:
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of Tag from a dict"""
if obj is None:
return None

View File

@ -75,7 +75,7 @@ class TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter(BaseMod
return _dict
@classmethod
def from_dict(cls, obj: Optional[Dict]) -> Optional[Self]:
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter from a dict"""
if obj is None:
return None

View File

@ -72,7 +72,7 @@ class TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter(BaseModel):
return _dict
@classmethod
def from_dict(cls, obj: Optional[Dict]) -> Optional[Self]:
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter from a dict"""
if obj is None:
return None

View File

@ -213,14 +213,13 @@ class RESTClientObject:
preload_content=False
)
# Pass a `string` parameter directly in the body to support
# other content types than Json when `body` argument is
# provided in serialized form
# other content types than JSON when `body` argument is
# provided in serialized form.
elif isinstance(body, str) or isinstance(body, bytes):
request_body = body
r = self.pool_manager.request(
method,
url,
body=request_body,
body=body,
timeout=timeout,
headers=headers,
preload_content=False

View File

@ -38,3 +38,34 @@ files = [
#"test", # auto-generated tests
"tests", # hand-written tests
]
# TODO: enable "strict" once all these individual checks are passing
# strict = true
# List from: https://mypy.readthedocs.io/en/stable/existing_code.html#introduce-stricter-options
warn_unused_configs = true
warn_redundant_casts = true
warn_unused_ignores = true
## Getting these passing should be easy
strict_equality = true
strict_concatenate = true
## Strongly recommend enabling this one as soon as you can
check_untyped_defs = true
## These shouldn't be too much additional work, but may be tricky to
## get passing if you use a lot of untyped libraries
disallow_subclassing_any = true
disallow_untyped_decorators = true
disallow_any_generics = true
### These next few are various gradations of forcing use of type annotations
#disallow_untyped_calls = true
#disallow_incomplete_defs = true
#disallow_untyped_defs = true
#
### This one isn't too hard to get passing, but return on investment is lower
#no_implicit_reexport = true
#
### This one can be tricky to get passing if you use a lot of untyped libraries
#warn_return_any = true

View File

@ -52,7 +52,7 @@ class TestManual(unittest.TestCase):
datetime_format_backup = api_instance.api_client.configuration.datetime_format # backup dateime_format
api_instance.api_client.configuration.datetime_format = "%Y-%m-%d %a %H:%M:%S%Z"
datetime_query = datetime.datetime.fromisoformat('2013-10-20T19:20:30-05:00') # datetime | (optional)
date_query = '2013-10-20' # date | (optional)
date_query = datetime.date(2013, 10, 20) # date | (optional)
string_query = 'string_query_example' # str | (optional)
# Test query parameter(s)
@ -66,7 +66,7 @@ class TestManual(unittest.TestCase):
def testDateTimeQueryWithDateTime(self):
api_instance = openapi_client.QueryApi()
datetime_query = datetime.datetime.fromisoformat('2013-10-20T19:20:30-05:00') # datetime | (optional)
date_query = '2013-10-20' # date | (optional)
date_query = datetime.date(2013, 10, 20) # date | (optional)
string_query = 'string_query_example' # str | (optional)
# Test query parameter(s)
@ -147,11 +147,14 @@ class TestManual(unittest.TestCase):
" \"status\": \"available\",\n"
" \"tags\": [{\"id\": 1, \"name\": \"None\"}]}")
pet = openapi_client.Pet.from_json(json_str)
assert pet is not None
self.assertEqual(pet.id, 1)
self.assertEqual(pet.status, "available")
self.assertEqual(pet.photo_urls, ["string"])
assert pet.tags is not None
self.assertEqual(pet.tags[0].id, 1)
self.assertEqual(pet.tags[0].name, "None")
assert pet.category is not None
self.assertEqual(pet.category.id, 1)
# test to_json
self.assertEqual(pet.to_json(),
@ -165,11 +168,14 @@ class TestManual(unittest.TestCase):
# test from_dict
pet2 = openapi_client.Pet.from_dict(pet.to_dict())
assert pet2 is not None
self.assertEqual(pet2.id, 1)
self.assertEqual(pet2.status, "available")
self.assertEqual(pet2.photo_urls, ["string"])
assert pet2.tags is not None
self.assertEqual(pet2.tags[0].id, 1)
self.assertEqual(pet2.tags[0].name, "None")
assert pet2.category is not None
self.assertEqual(pet2.category.id, 1)
def echoServerResponseParaserTest(self):

View File

@ -18,7 +18,7 @@ from typing import Any, Dict, List, Optional, Tuple, Union
from typing_extensions import Annotated
from openapi_client.api_client import ApiClient
from openapi_client.api_client import ApiClient, RequestSerialized
from openapi_client.api_response import ApiResponse
from openapi_client.rest import RESTResponseType
@ -227,7 +227,7 @@ class AuthApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -470,7 +470,7 @@ class AuthApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None

View File

@ -23,7 +23,7 @@ from typing_extensions import Annotated
from openapi_client.models.pet import Pet
from openapi_client.models.tag import Tag
from openapi_client.api_client import ApiClient
from openapi_client.api_client import ApiClient, RequestSerialized
from openapi_client.api_response import ApiResponse
from openapi_client.rest import RESTResponseType
@ -232,7 +232,7 @@ class BodyApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -487,7 +487,7 @@ class BodyApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -762,7 +762,7 @@ class BodyApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -1033,7 +1033,7 @@ class BodyApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -1303,7 +1303,7 @@ class BodyApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -1573,7 +1573,7 @@ class BodyApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -1843,7 +1843,7 @@ class BodyApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -2113,7 +2113,7 @@ class BodyApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -2383,7 +2383,7 @@ class BodyApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None

View File

@ -20,7 +20,7 @@ from typing_extensions import Annotated
from pydantic import StrictBool, StrictInt, StrictStr
from typing import Optional
from openapi_client.api_client import ApiClient
from openapi_client.api_client import ApiClient, RequestSerialized
from openapi_client.api_response import ApiResponse
from openapi_client.rest import RESTResponseType
@ -268,7 +268,7 @@ class FormApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -607,7 +607,7 @@ class FormApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None

View File

@ -21,7 +21,7 @@ from pydantic import StrictBool, StrictInt, StrictStr, field_validator
from typing import Optional
from openapi_client.models.string_enum_ref import StringEnumRef
from openapi_client.api_client import ApiClient
from openapi_client.api_client import ApiClient, RequestSerialized
from openapi_client.api_response import ApiResponse
from openapi_client.rest import RESTResponseType
@ -295,7 +295,7 @@ class HeaderApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None

View File

@ -20,7 +20,7 @@ from typing_extensions import Annotated
from pydantic import StrictInt, StrictStr, field_validator
from openapi_client.models.string_enum_ref import StringEnumRef
from openapi_client.api_client import ApiClient
from openapi_client.api_client import ApiClient, RequestSerialized
from openapi_client.api_response import ApiResponse
from openapi_client.rest import RESTResponseType
@ -281,7 +281,7 @@ class PathApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None

View File

@ -24,7 +24,7 @@ from openapi_client.models.pet import Pet
from openapi_client.models.string_enum_ref import StringEnumRef
from openapi_client.models.test_query_style_form_explode_true_array_string_query_object_parameter import TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter
from openapi_client.api_client import ApiClient
from openapi_client.api_client import ApiClient, RequestSerialized
from openapi_client.api_response import ApiResponse
from openapi_client.rest import RESTResponseType
@ -259,7 +259,7 @@ class QueryApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -548,7 +548,7 @@ class QueryApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -859,7 +859,7 @@ class QueryApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -1126,7 +1126,7 @@ class QueryApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -1385,7 +1385,7 @@ class QueryApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -1644,7 +1644,7 @@ class QueryApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -1903,7 +1903,7 @@ class QueryApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -2162,7 +2162,7 @@ class QueryApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None

View File

@ -22,10 +22,10 @@ import re
import tempfile
from urllib.parse import quote
from typing import Tuple, Optional, List
from typing import Tuple, Optional, List, Dict
from openapi_client.configuration import Configuration
from openapi_client.api_response import ApiResponse
from openapi_client.api_response import ApiResponse, T as ApiResponseT
import openapi_client.models
from openapi_client import rest
from openapi_client.exceptions import (
@ -38,6 +38,7 @@ from openapi_client.exceptions import (
ServiceException
)
RequestSerialized = Tuple[str, str, Dict[str, str], Optional[str], List[str]]
class ApiClient:
"""Generic API client for OpenAPI client library builds.
@ -147,7 +148,7 @@ class ApiClient:
collection_formats=None,
_host=None,
_request_auth=None
) -> Tuple:
) -> RequestSerialized:
"""Builds the HTTP request params needed by the request.
:param method: Method to call.
@ -280,8 +281,8 @@ class ApiClient:
def response_deserialize(
self,
response_data: rest.RESTResponse,
response_types_map=None
) -> ApiResponse:
response_types_map: Optional[Dict[str, ApiResponseT]]=None
) -> ApiResponse[ApiResponseT]:
"""Deserializes response into an object.
:param response_data: RESTResponse object to be deserialized.
:param response_types_map: dict of response types.
@ -402,12 +403,16 @@ class ApiClient:
if isinstance(klass, str):
if klass.startswith('List['):
sub_kls = re.match(r'List\[(.*)]', klass).group(1)
m = re.match(r'List\[(.*)]', klass)
assert m is not None, "Malformed List type definition"
sub_kls = m.group(1)
return [self.__deserialize(sub_data, sub_kls)
for sub_data in data]
if klass.startswith('Dict['):
sub_kls = re.match(r'Dict\[([^,]*), (.*)]', klass).group(2)
m = re.match(r'Dict\[([^,]*), (.*)]', klass)
assert m is not None, "Malformed Dict type definition"
sub_kls = m.group(2)
return {k: self.__deserialize(v, sub_kls)
for k, v in data.items()}
@ -435,7 +440,7 @@ class ApiClient:
:param dict collection_formats: Parameter collection formats
:return: Parameters as list of tuples, collections formatted
"""
new_params = []
new_params: List[Tuple[str, str]] = []
if collection_formats is None:
collection_formats = {}
for k, v in params.items() if isinstance(params, dict) else params:
@ -465,7 +470,7 @@ class ApiClient:
:param dict collection_formats: Parameter collection formats
:return: URL query string (e.g. a=Hello%20World&b=123)
"""
new_params = []
new_params: List[Tuple[str, str]] = []
if collection_formats is None:
collection_formats = {}
for k, v in params.items() if isinstance(params, dict) else params:
@ -650,10 +655,12 @@ class ApiClient:
content_disposition = response.getheader("Content-Disposition")
if content_disposition:
filename = re.search(
m = re.search(
r'filename=[\'"]?([^\'"\s]+)[\'"]?',
content_disposition
).group(1)
)
assert m is not None, "Unexpected 'content-disposition' header value"
filename = m.group(1)
path = os.path.join(os.path.dirname(path), filename)
with open(path, "wb") as f:

View File

@ -15,8 +15,10 @@
import copy
import logging
from logging import FileHandler
import multiprocessing
import sys
from typing import Optional
import urllib3
import http.client as httplib
@ -133,7 +135,7 @@ conf = openapi_client.Configuration(
self.logger_stream_handler = None
"""Log stream handler
"""
self.logger_file_handler = None
self.logger_file_handler: Optional[FileHandler] = None
"""Log file handler
"""
self.logger_file = None
@ -173,7 +175,7 @@ conf = openapi_client.Configuration(
cpu_count * 5 is used as default value to increase performance.
"""
self.proxy = None
self.proxy: Optional[str] = None
"""Proxy URL
"""
self.proxy_headers = None

View File

@ -73,7 +73,7 @@ class Bird(BaseModel):
return _dict
@classmethod
def from_dict(cls, obj: Optional[Dict]) -> Optional[Self]:
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of Bird from a dict"""
if obj is None:
return None

View File

@ -73,7 +73,7 @@ class Category(BaseModel):
return _dict
@classmethod
def from_dict(cls, obj: Optional[Dict]) -> Optional[Self]:
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of Category from a dict"""
if obj is None:
return None

View File

@ -76,7 +76,7 @@ class DataQuery(Query):
return _dict
@classmethod
def from_dict(cls, obj: Optional[Dict]) -> Optional[Self]:
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of DataQuery from a dict"""
if obj is None:
return None

View File

@ -106,7 +106,7 @@ class DefaultValue(BaseModel):
return _dict
@classmethod
def from_dict(cls, obj: Optional[Dict]) -> Optional[Self]:
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of DefaultValue from a dict"""
if obj is None:
return None

View File

@ -75,7 +75,7 @@ class NumberPropertiesOnly(BaseModel):
return _dict
@classmethod
def from_dict(cls, obj: Optional[Dict]) -> Optional[Self]:
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of NumberPropertiesOnly from a dict"""
if obj is None:
return None

View File

@ -99,7 +99,7 @@ class Pet(BaseModel):
return _dict
@classmethod
def from_dict(cls, obj: Optional[Dict]) -> Optional[Self]:
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of Pet from a dict"""
if obj is None:
return None

View File

@ -84,7 +84,7 @@ class Query(BaseModel):
return _dict
@classmethod
def from_dict(cls, obj: Dict) -> Optional[Self]:
def from_dict(cls, obj: Dict[str, Any]) -> Optional[Self]:
"""Create an instance of Query from a dict"""

View File

@ -73,7 +73,7 @@ class Tag(BaseModel):
return _dict
@classmethod
def from_dict(cls, obj: Optional[Dict]) -> Optional[Self]:
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of Tag from a dict"""
if obj is None:
return None

View File

@ -75,7 +75,7 @@ class TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter(BaseMod
return _dict
@classmethod
def from_dict(cls, obj: Optional[Dict]) -> Optional[Self]:
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of TestQueryStyleDeepObjectExplodeTrueObjectAllOfQueryObjectParameter from a dict"""
if obj is None:
return None

View File

@ -72,7 +72,7 @@ class TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter(BaseModel):
return _dict
@classmethod
def from_dict(cls, obj: Optional[Dict]) -> Optional[Self]:
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter from a dict"""
if obj is None:
return None

View File

@ -213,14 +213,13 @@ class RESTClientObject:
preload_content=False
)
# Pass a `string` parameter directly in the body to support
# other content types than Json when `body` argument is
# provided in serialized form
# other content types than JSON when `body` argument is
# provided in serialized form.
elif isinstance(body, str) or isinstance(body, bytes):
request_body = body
r = self.pool_manager.request(
method,
url,
body=request_body,
body=body,
timeout=timeout,
headers=headers,
preload_content=False

View File

@ -38,3 +38,34 @@ files = [
#"test", # auto-generated tests
"tests", # hand-written tests
]
# TODO: enable "strict" once all these individual checks are passing
# strict = true
# List from: https://mypy.readthedocs.io/en/stable/existing_code.html#introduce-stricter-options
warn_unused_configs = true
warn_redundant_casts = true
warn_unused_ignores = true
## Getting these passing should be easy
strict_equality = true
strict_concatenate = true
## Strongly recommend enabling this one as soon as you can
check_untyped_defs = true
## These shouldn't be too much additional work, but may be tricky to
## get passing if you use a lot of untyped libraries
disallow_subclassing_any = true
disallow_untyped_decorators = true
disallow_any_generics = true
### These next few are various gradations of forcing use of type annotations
#disallow_untyped_calls = true
#disallow_incomplete_defs = true
#disallow_untyped_defs = true
#
### This one isn't too hard to get passing, but return on investment is lower
#no_implicit_reexport = true
#
### This one can be tricky to get passing if you use a lot of untyped libraries
#warn_return_any = true

View File

@ -85,7 +85,7 @@ class TestManual(unittest.TestCase):
datetime_format_backup = api_instance.api_client.configuration.datetime_format # backup dateime_format
api_instance.api_client.configuration.datetime_format = "%Y-%m-%d %a %H:%M:%S%Z"
datetime_query = datetime.datetime.fromisoformat('2013-10-20T19:20:30-05:00') # datetime | (optional)
date_query = '2013-10-20' # date | (optional)
date_query = datetime.date(2013, 10, 20) # date | (optional)
string_query = 'string_query_example' # str | (optional)
# Test query parameter(s)
@ -99,7 +99,7 @@ class TestManual(unittest.TestCase):
def testDateTimeQueryWithDateTime(self):
api_instance = openapi_client.QueryApi()
datetime_query = datetime.datetime.fromisoformat('2013-10-20T19:20:30-05:00') # datetime | (optional)
date_query = '2013-10-20' # date | (optional)
date_query = datetime.date(2013, 10, 20) # date | (optional)
string_query = 'string_query_example' # str | (optional)
# Test query parameter(s)
@ -116,12 +116,14 @@ class TestManual(unittest.TestCase):
def testNumberPropertiesOnly(self):
n = openapi_client.NumberPropertiesOnly.from_json('{"number": 123, "float": 456, "double": 34}')
assert n is not None
self.assertEqual(n.number, 123)
# TODO: pydantic v2: this field name override the default `float` type
# self.assertEqual(n.float, 456)
self.assertEqual(n.double, 34)
n = openapi_client.NumberPropertiesOnly.from_json('{"number": 123.1, "float": 456.2, "double": 34.3}')
assert n is not None
self.assertEqual(n.number, 123.1)
# TODO: pydantic v2: this field name override the default `float` type
# self.assertEqual(n.float, 456.2)
@ -187,11 +189,14 @@ class TestManual(unittest.TestCase):
" \"status\": \"available\",\n"
" \"tags\": [{\"id\": 1, \"name\": \"None\"}]}")
pet = openapi_client.Pet.from_json(json_str)
assert pet is not None
self.assertEqual(pet.id, 1)
self.assertEqual(pet.status, "available")
self.assertEqual(pet.photo_urls, ["string"])
assert pet.tags is not None
self.assertEqual(pet.tags[0].id, 1)
self.assertEqual(pet.tags[0].name, "None")
assert pet.category is not None
self.assertEqual(pet.category.id, 1)
# test to_json
self.assertEqual(pet.to_json(),
@ -205,11 +210,14 @@ class TestManual(unittest.TestCase):
# test from_dict
pet2 = openapi_client.Pet.from_dict(pet.to_dict())
assert pet2 is not None
self.assertEqual(pet2.id, 1)
self.assertEqual(pet2.status, "available")
self.assertEqual(pet2.photo_urls, ["string"])
assert pet2.tags is not None
self.assertEqual(pet2.tags[0].id, 1)
self.assertEqual(pet2.tags[0].name, "None")
assert pet2.category is not None
self.assertEqual(pet2.category.id, 1)
def test_parameters_to_url_query_boolean_value(self):

View File

@ -20,7 +20,7 @@ from pydantic import Field
from typing_extensions import Annotated
from petstore_api.models.client import Client
from petstore_api.api_client import ApiClient
from petstore_api.api_client import ApiClient, RequestSerialized
from petstore_api.api_response import ApiResponse
from petstore_api.rest import RESTResponseType
@ -242,7 +242,7 @@ class AnotherFakeApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None

View File

@ -18,7 +18,7 @@ from typing_extensions import Annotated
from petstore_api.models.foo_get_default_response import FooGetDefaultResponse
from petstore_api.api_client import ApiClient
from petstore_api.api_client import ApiClient, RequestSerialized
from petstore_api.api_response import ApiResponse
from petstore_api.rest import RESTResponseType
@ -221,7 +221,7 @@ class DefaultApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None

View File

@ -31,7 +31,7 @@ from petstore_api.models.tag import Tag
from petstore_api.models.test_inline_freeform_additional_properties_request import TestInlineFreeformAdditionalPropertiesRequest
from petstore_api.models.user import User
from petstore_api.api_client import ApiClient
from petstore_api.api_client import ApiClient, RequestSerialized
from petstore_api.api_response import ApiResponse
from petstore_api.rest import RESTResponseType
@ -250,7 +250,7 @@ class FakeApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -511,7 +511,7 @@ class FakeApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -748,7 +748,7 @@ class FakeApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -1026,7 +1026,7 @@ class FakeApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -1298,7 +1298,7 @@ class FakeApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -1568,7 +1568,7 @@ class FakeApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -1838,7 +1838,7 @@ class FakeApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -2108,7 +2108,7 @@ class FakeApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -2378,7 +2378,7 @@ class FakeApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -2632,7 +2632,7 @@ class FakeApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -2871,7 +2871,7 @@ class FakeApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -3123,7 +3123,7 @@ class FakeApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -3376,7 +3376,7 @@ class FakeApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -3640,7 +3640,7 @@ class FakeApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -3909,7 +3909,7 @@ class FakeApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -4183,7 +4183,7 @@ class FakeApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -4451,7 +4451,7 @@ class FakeApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -4731,7 +4731,7 @@ class FakeApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -4987,7 +4987,7 @@ class FakeApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -5427,7 +5427,7 @@ class FakeApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -5710,7 +5710,7 @@ class FakeApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -6030,7 +6030,7 @@ class FakeApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -6300,7 +6300,7 @@ class FakeApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -6564,7 +6564,7 @@ class FakeApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -6841,7 +6841,7 @@ class FakeApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -7185,7 +7185,7 @@ class FakeApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None

View File

@ -20,7 +20,7 @@ from pydantic import Field
from typing_extensions import Annotated
from petstore_api.models.client import Client
from petstore_api.api_client import ApiClient
from petstore_api.api_client import ApiClient, RequestSerialized
from petstore_api.api_response import ApiResponse
from petstore_api.rest import RESTResponseType
@ -242,7 +242,7 @@ class FakeClassnameTags123Api:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None

View File

@ -22,7 +22,7 @@ from typing_extensions import Annotated
from petstore_api.models.model_api_response import ModelApiResponse
from petstore_api.models.pet import Pet
from petstore_api.api_client import ApiClient
from petstore_api.api_client import ApiClient, RequestSerialized
from petstore_api.api_response import ApiResponse
from petstore_api.rest import RESTResponseType
@ -247,7 +247,7 @@ class PetApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -530,7 +530,7 @@ class PetApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -787,7 +787,7 @@ class PetApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -1056,7 +1056,7 @@ class PetApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -1325,7 +1325,7 @@ class PetApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -1593,7 +1593,7 @@ class PetApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -1889,7 +1889,7 @@ class PetApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -2184,7 +2184,7 @@ class PetApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -2485,7 +2485,7 @@ class PetApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None

View File

@ -20,7 +20,7 @@ from pydantic import Field, StrictStr
from typing_extensions import Annotated
from petstore_api.models.order import Order
from petstore_api.api_client import ApiClient
from petstore_api.api_client import ApiClient, RequestSerialized
from petstore_api.api_response import ApiResponse
from petstore_api.rest import RESTResponseType
@ -245,7 +245,7 @@ class StoreApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -483,7 +483,7 @@ class StoreApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -745,7 +745,7 @@ class StoreApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -1006,7 +1006,7 @@ class StoreApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None

View File

@ -21,7 +21,7 @@ from typing import List
from typing_extensions import Annotated
from petstore_api.models.user import User
from petstore_api.api_client import ApiClient
from petstore_api.api_client import ApiClient, RequestSerialized
from petstore_api.api_response import ApiResponse
from petstore_api.rest import RESTResponseType
@ -240,7 +240,7 @@ class UserApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_hosts = [
'http://petstore.swagger.io/v2',
@ -506,7 +506,7 @@ class UserApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -768,7 +768,7 @@ class UserApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -1036,7 +1036,7 @@ class UserApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -1293,7 +1293,7 @@ class UserApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -1567,7 +1567,7 @@ class UserApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -1815,7 +1815,7 @@ class UserApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None
@ -2080,7 +2080,7 @@ class UserApi:
_content_type,
_headers,
_host_index,
) -> Tuple:
) -> RequestSerialized:
_host = None

View File

@ -21,10 +21,10 @@ import re
import tempfile
from urllib.parse import quote
from typing import Tuple, Optional, List
from typing import Tuple, Optional, List, Dict
from petstore_api.configuration import Configuration
from petstore_api.api_response import ApiResponse
from petstore_api.api_response import ApiResponse, T as ApiResponseT
import petstore_api.models
from petstore_api import rest
from petstore_api.exceptions import (
@ -37,6 +37,7 @@ from petstore_api.exceptions import (
ServiceException
)
RequestSerialized = Tuple[str, str, Dict[str, str], Optional[str], List[str]]
class ApiClient:
"""Generic API client for OpenAPI client library builds.
@ -149,7 +150,7 @@ class ApiClient:
collection_formats=None,
_host=None,
_request_auth=None
) -> Tuple:
) -> RequestSerialized:
"""Builds the HTTP request params needed by the request.
:param method: Method to call.
@ -282,8 +283,8 @@ class ApiClient:
def response_deserialize(
self,
response_data: rest.RESTResponse,
response_types_map=None
) -> ApiResponse:
response_types_map: Optional[Dict[str, ApiResponseT]]=None
) -> ApiResponse[ApiResponseT]:
"""Deserializes response into an object.
:param response_data: RESTResponse object to be deserialized.
:param response_types_map: dict of response types.
@ -404,12 +405,16 @@ class ApiClient:
if isinstance(klass, str):
if klass.startswith('List['):
sub_kls = re.match(r'List\[(.*)]', klass).group(1)
m = re.match(r'List\[(.*)]', klass)
assert m is not None, "Malformed List type definition"
sub_kls = m.group(1)
return [self.__deserialize(sub_data, sub_kls)
for sub_data in data]
if klass.startswith('Dict['):
sub_kls = re.match(r'Dict\[([^,]*), (.*)]', klass).group(2)
m = re.match(r'Dict\[([^,]*), (.*)]', klass)
assert m is not None, "Malformed Dict type definition"
sub_kls = m.group(2)
return {k: self.__deserialize(v, sub_kls)
for k, v in data.items()}
@ -437,7 +442,7 @@ class ApiClient:
:param dict collection_formats: Parameter collection formats
:return: Parameters as list of tuples, collections formatted
"""
new_params = []
new_params: List[Tuple[str, str]] = []
if collection_formats is None:
collection_formats = {}
for k, v in params.items() if isinstance(params, dict) else params:
@ -467,7 +472,7 @@ class ApiClient:
:param dict collection_formats: Parameter collection formats
:return: URL query string (e.g. a=Hello%20World&b=123)
"""
new_params = []
new_params: List[Tuple[str, str]] = []
if collection_formats is None:
collection_formats = {}
for k, v in params.items() if isinstance(params, dict) else params:
@ -659,10 +664,12 @@ class ApiClient:
content_disposition = response.getheader("Content-Disposition")
if content_disposition:
filename = re.search(
m = re.search(
r'filename=[\'"]?([^\'"\s]+)[\'"]?',
content_disposition
).group(1)
)
assert m is not None, "Unexpected 'content-disposition' header value"
filename = m.group(1)
path = os.path.join(os.path.dirname(path), filename)
with open(path, "wb") as f:

View File

@ -14,7 +14,9 @@
import copy
import logging
from logging import FileHandler
import sys
from typing import Optional
import urllib3
import http.client as httplib
@ -197,7 +199,7 @@ conf = petstore_api.Configuration(
self.logger_stream_handler = None
"""Log stream handler
"""
self.logger_file_handler = None
self.logger_file_handler: Optional[FileHandler] = None
"""Log file handler
"""
self.logger_file = None
@ -234,7 +236,7 @@ conf = petstore_api.Configuration(
Default values is 100, None means no-limit.
"""
self.proxy = None
self.proxy: Optional[str] = None
"""Proxy URL
"""
self.proxy_headers = None

View File

@ -79,7 +79,7 @@ class AdditionalPropertiesAnyType(BaseModel):
return _dict
@classmethod
def from_dict(cls, obj: Optional[Dict]) -> Optional[Self]:
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of AdditionalPropertiesAnyType from a dict"""
if obj is None:
return None

View File

@ -72,7 +72,7 @@ class AdditionalPropertiesClass(BaseModel):
return _dict
@classmethod
def from_dict(cls, obj: Optional[Dict]) -> Optional[Self]:
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of AdditionalPropertiesClass from a dict"""
if obj is None:
return None

View File

@ -79,7 +79,7 @@ class AdditionalPropertiesObject(BaseModel):
return _dict
@classmethod
def from_dict(cls, obj: Optional[Dict]) -> Optional[Self]:
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of AdditionalPropertiesObject from a dict"""
if obj is None:
return None

View File

@ -79,7 +79,7 @@ class AdditionalPropertiesWithDescriptionOnly(BaseModel):
return _dict
@classmethod
def from_dict(cls, obj: Optional[Dict]) -> Optional[Self]:
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of AdditionalPropertiesWithDescriptionOnly from a dict"""
if obj is None:
return None

View File

@ -73,7 +73,7 @@ class AllOfWithSingleRef(BaseModel):
return _dict
@classmethod
def from_dict(cls, obj: Optional[Dict]) -> Optional[Self]:
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of AllOfWithSingleRef from a dict"""
if obj is None:
return None

View File

@ -46,7 +46,7 @@ class Animal(BaseModel):
}
@classmethod
def get_discriminator_value(cls, obj: Dict) -> Optional[str]:
def get_discriminator_value(cls, obj: Dict[str, Any]) -> Optional[str]:
"""Returns the discriminator value (object type) of the data"""
discriminator_value = obj[cls.__discriminator_property_name]
if discriminator_value:
@ -89,7 +89,7 @@ class Animal(BaseModel):
return _dict
@classmethod
def from_dict(cls, obj: Dict) -> Optional[Union[Self, Self]]:
def from_dict(cls, obj: Dict[str, Any]) -> Optional[Union[Self, Self]]:
"""Create an instance of Animal from a dict"""
# look up the object type based on discriminator mapping
object_type = cls.get_discriminator_value(obj)

View File

@ -87,7 +87,7 @@ class AnyOfColor(BaseModel):
return v
@classmethod
def from_dict(cls, obj: dict) -> Self:
def from_dict(cls, obj: Dict[str, Any]) -> Self:
return cls.from_json(json.dumps(obj))
@classmethod
@ -139,7 +139,7 @@ class AnyOfColor(BaseModel):
else:
return json.dumps(self.actual_instance)
def to_dict(self) -> Optional[Union[Dict, List[int], str]]:
def to_dict(self) -> Optional[Union[Dict[str, Any], List[int], str]]:
"""Returns the dict representation of the actual instance"""
if self.actual_instance is None:
return None

View File

@ -80,7 +80,7 @@ class AnyOfPig(BaseModel):
return v
@classmethod
def from_dict(cls, obj: dict) -> Self:
def from_dict(cls, obj: Dict[str, Any]) -> Self:
return cls.from_json(json.dumps(obj))
@classmethod
@ -117,7 +117,7 @@ class AnyOfPig(BaseModel):
else:
return json.dumps(self.actual_instance)
def to_dict(self) -> Optional[Union[Dict, BasquePig, DanishPig]]:
def to_dict(self) -> Optional[Union[Dict[str, Any], BasquePig, DanishPig]]:
"""Returns the dict representation of the actual instance"""
if self.actual_instance is None:
return None

View File

@ -81,7 +81,7 @@ class ArrayOfArrayOfModel(BaseModel):
return _dict
@classmethod
def from_dict(cls, obj: Optional[Dict]) -> Optional[Self]:
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of ArrayOfArrayOfModel from a dict"""
if obj is None:
return None

View File

@ -71,7 +71,7 @@ class ArrayOfArrayOfNumberOnly(BaseModel):
return _dict
@classmethod
def from_dict(cls, obj: Optional[Dict]) -> Optional[Self]:
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of ArrayOfArrayOfNumberOnly from a dict"""
if obj is None:
return None

View File

@ -71,7 +71,7 @@ class ArrayOfNumberOnly(BaseModel):
return _dict
@classmethod
def from_dict(cls, obj: Optional[Dict]) -> Optional[Self]:
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of ArrayOfNumberOnly from a dict"""
if obj is None:
return None

View File

@ -84,7 +84,7 @@ class ArrayTest(BaseModel):
return _dict
@classmethod
def from_dict(cls, obj: Optional[Dict]) -> Optional[Self]:
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of ArrayTest from a dict"""
if obj is None:
return None

View File

@ -72,7 +72,7 @@ class BasquePig(BaseModel):
return _dict
@classmethod
def from_dict(cls, obj: Optional[Dict]) -> Optional[Self]:
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of BasquePig from a dict"""
if obj is None:
return None

View File

@ -76,7 +76,7 @@ class Capitalization(BaseModel):
return _dict
@classmethod
def from_dict(cls, obj: Optional[Dict]) -> Optional[Self]:
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of Capitalization from a dict"""
if obj is None:
return None

View File

@ -72,7 +72,7 @@ class Cat(Animal):
return _dict
@classmethod
def from_dict(cls, obj: Optional[Dict]) -> Optional[Self]:
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of Cat from a dict"""
if obj is None:
return None

View File

@ -72,7 +72,7 @@ class Category(BaseModel):
return _dict
@classmethod
def from_dict(cls, obj: Optional[Dict]) -> Optional[Self]:
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of Category from a dict"""
if obj is None:
return None

View File

@ -75,7 +75,7 @@ class CircularReferenceModel(BaseModel):
return _dict
@classmethod
def from_dict(cls, obj: Optional[Dict]) -> Optional[Self]:
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of CircularReferenceModel from a dict"""
if obj is None:
return None

View File

@ -71,7 +71,7 @@ class ClassModel(BaseModel):
return _dict
@classmethod
def from_dict(cls, obj: Optional[Dict]) -> Optional[Self]:
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of ClassModel from a dict"""
if obj is None:
return None

View File

@ -71,7 +71,7 @@ class Client(BaseModel):
return _dict
@classmethod
def from_dict(cls, obj: Optional[Dict]) -> Optional[Self]:
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of Client from a dict"""
if obj is None:
return None

View File

@ -89,11 +89,11 @@ class Color(BaseModel):
return v
@classmethod
def from_dict(cls, obj: dict) -> Self:
def from_dict(cls, obj: Union[str, Dict[str, Any]]) -> Self:
return cls.from_json(json.dumps(obj))
@classmethod
def from_json(cls, json_str: str) -> Self:
def from_json(cls, json_str: Optional[str]) -> Self:
"""Returns the object represented by the json string"""
instance = cls.model_construct()
if json_str is None:
@ -149,7 +149,7 @@ class Color(BaseModel):
else:
return json.dumps(self.actual_instance)
def to_dict(self) -> Optional[Union[Dict, List[int], str]]:
def to_dict(self) -> Optional[Union[Dict[str, Any], List[int], str]]:
"""Returns the dict representation of the actual instance"""
if self.actual_instance is None:
return None

View File

@ -76,7 +76,7 @@ class Creature(BaseModel):
return _dict
@classmethod
def from_dict(cls, obj: Optional[Dict]) -> Optional[Self]:
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of Creature from a dict"""
if obj is None:
return None

View File

@ -71,7 +71,7 @@ class CreatureInfo(BaseModel):
return _dict
@classmethod
def from_dict(cls, obj: Optional[Dict]) -> Optional[Self]:
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of CreatureInfo from a dict"""
if obj is None:
return None

View File

@ -72,7 +72,7 @@ class DanishPig(BaseModel):
return _dict
@classmethod
def from_dict(cls, obj: Optional[Dict]) -> Optional[Self]:
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of DanishPig from a dict"""
if obj is None:
return None

View File

@ -71,7 +71,7 @@ class DeprecatedObject(BaseModel):
return _dict
@classmethod
def from_dict(cls, obj: Optional[Dict]) -> Optional[Self]:
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of DeprecatedObject from a dict"""
if obj is None:
return None

View File

@ -72,7 +72,7 @@ class Dog(Animal):
return _dict
@classmethod
def from_dict(cls, obj: Optional[Dict]) -> Optional[Self]:
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of Dog from a dict"""
if obj is None:
return None

View File

@ -75,7 +75,7 @@ class DummyModel(BaseModel):
return _dict
@classmethod
def from_dict(cls, obj: Optional[Dict]) -> Optional[Self]:
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of DummyModel from a dict"""
if obj is None:
return None

View File

@ -93,7 +93,7 @@ class EnumArrays(BaseModel):
return _dict
@classmethod
def from_dict(cls, obj: Optional[Dict]) -> Optional[Self]:
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of EnumArrays from a dict"""
if obj is None:
return None

View File

@ -135,7 +135,7 @@ class EnumTest(BaseModel):
return _dict
@classmethod
def from_dict(cls, obj: Optional[Dict]) -> Optional[Self]:
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of EnumTest from a dict"""
if obj is None:
return None

View File

@ -71,7 +71,7 @@ class File(BaseModel):
return _dict
@classmethod
def from_dict(cls, obj: Optional[Dict]) -> Optional[Self]:
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of File from a dict"""
if obj is None:
return None

View File

@ -83,7 +83,7 @@ class FileSchemaTestClass(BaseModel):
return _dict
@classmethod
def from_dict(cls, obj: Optional[Dict]) -> Optional[Self]:
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of FileSchemaTestClass from a dict"""
if obj is None:
return None

View File

@ -75,7 +75,7 @@ class FirstRef(BaseModel):
return _dict
@classmethod
def from_dict(cls, obj: Optional[Dict]) -> Optional[Self]:
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of FirstRef from a dict"""
if obj is None:
return None

View File

@ -71,7 +71,7 @@ class Foo(BaseModel):
return _dict
@classmethod
def from_dict(cls, obj: Optional[Dict]) -> Optional[Self]:
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of Foo from a dict"""
if obj is None:
return None

View File

@ -75,7 +75,7 @@ class FooGetDefaultResponse(BaseModel):
return _dict
@classmethod
def from_dict(cls, obj: Optional[Dict]) -> Optional[Self]:
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of FooGetDefaultResponse from a dict"""
if obj is None:
return None

View File

@ -130,7 +130,7 @@ class FormatTest(BaseModel):
return _dict
@classmethod
def from_dict(cls, obj: Optional[Dict]) -> Optional[Self]:
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of FormatTest from a dict"""
if obj is None:
return None

View File

@ -76,7 +76,7 @@ class HasOnlyReadOnly(BaseModel):
return _dict
@classmethod
def from_dict(cls, obj: Optional[Dict]) -> Optional[Self]:
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of HasOnlyReadOnly from a dict"""
if obj is None:
return None

View File

@ -76,7 +76,7 @@ class HealthCheckResult(BaseModel):
return _dict
@classmethod
def from_dict(cls, obj: Optional[Dict]) -> Optional[Self]:
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of HealthCheckResult from a dict"""
if obj is None:
return None

View File

@ -71,7 +71,7 @@ class InnerDictWithProperty(BaseModel):
return _dict
@classmethod
def from_dict(cls, obj: Optional[Dict]) -> Optional[Self]:
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of InnerDictWithProperty from a dict"""
if obj is None:
return None

View File

@ -78,7 +78,7 @@ class IntOrString(BaseModel):
return v
@classmethod
def from_dict(cls, obj: dict) -> Self:
def from_dict(cls, obj: Union[str, Dict[str, Any]]) -> Self:
return cls.from_json(json.dumps(obj))
@classmethod
@ -126,7 +126,7 @@ class IntOrString(BaseModel):
else:
return json.dumps(self.actual_instance)
def to_dict(self) -> Optional[Union[Dict, int, str]]:
def to_dict(self) -> Optional[Union[Dict[str, Any], int, str]]:
"""Returns the dict representation of the actual instance"""
if self.actual_instance is None:
return None

View File

@ -71,7 +71,7 @@ class ListClass(BaseModel):
return _dict
@classmethod
def from_dict(cls, obj: Optional[Dict]) -> Optional[Self]:
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
"""Create an instance of ListClass from a dict"""
if obj is None:
return None

Some files were not shown because too many files have changed in this diff Show More