python: adjust basic typing information (#17511)

* python: adjust basic typing information

This is an initial pass to fix and adjust the typing information for the
generated client. This is enough to have mypy runnning without complains
on all the (modern) generated clients (Pydantic v1 code is not checked
for instance)

mypy is also now run directly in the CI, so further changes will also be
checked and thus, will need to be compliant with good typing
information.

Note that this doesn't *fully* type all the code: mypy is not run in
"strict" mode and there are still many functions/methods/attributes
which are still not fully typed, but it's a first good step in that
direction.

* ApiResponse's raw_data can't be None

* Fix indentation

* Revert test changes

* run mypy on tests/ directory

* don't forcefully convert the client response headers to dict

* override petstore ApiResponse model

* adjust type of 'any/one_of_schemas' fields
This commit is contained in:
Jonathan Ballet
2024-01-06 08:40:42 +01:00
committed by GitHub
parent 4acbd69c3d
commit 22a0fc1727
257 changed files with 3168 additions and 1975 deletions

View File

@@ -72,56 +72,45 @@ class RESTClientObject:
else:
cert_reqs = ssl.CERT_NONE
addition_pool_args = {}
pool_args = {
"cert_reqs": cert_reqs,
"ca_certs": configuration.ssl_ca_cert,
"cert_file": configuration.cert_file,
"key_file": configuration.key_file,
}
if configuration.assert_hostname is not None:
addition_pool_args['assert_hostname'] = (
pool_args['assert_hostname'] = (
configuration.assert_hostname
)
if configuration.retries is not None:
addition_pool_args['retries'] = configuration.retries
pool_args['retries'] = configuration.retries
if configuration.tls_server_name:
addition_pool_args['server_hostname'] = configuration.tls_server_name
pool_args['server_hostname'] = configuration.tls_server_name
if configuration.socket_options is not None:
addition_pool_args['socket_options'] = configuration.socket_options
pool_args['socket_options'] = configuration.socket_options
if configuration.connection_pool_maxsize is not None:
addition_pool_args['maxsize'] = configuration.connection_pool_maxsize
pool_args['maxsize'] = configuration.connection_pool_maxsize
# https pool manager
self.pool_manager: urllib3.PoolManager
if configuration.proxy:
if is_socks_proxy_url(configuration.proxy):
from urllib3.contrib.socks import SOCKSProxyManager
self.pool_manager = SOCKSProxyManager(
cert_reqs=cert_reqs,
ca_certs=configuration.ssl_ca_cert,
cert_file=configuration.cert_file,
key_file=configuration.key_file,
proxy_url=configuration.proxy,
headers=configuration.proxy_headers,
**addition_pool_args
)
pool_args["proxy_url"] = configuration.proxy
pool_args["headers"] = configuration.proxy_headers
self.pool_manager = SOCKSProxyManager(**pool_args)
else:
self.pool_manager = urllib3.ProxyManager(
cert_reqs=cert_reqs,
ca_certs=configuration.ssl_ca_cert,
cert_file=configuration.cert_file,
key_file=configuration.key_file,
proxy_url=configuration.proxy,
proxy_headers=configuration.proxy_headers,
**addition_pool_args
)
pool_args["proxy_url"] = configuration.proxy
pool_args["proxy_headers"] = configuration.proxy_headers
self.pool_manager = urllib3.ProxyManager(**pool_args)
else:
self.pool_manager = urllib3.PoolManager(
cert_reqs=cert_reqs,
ca_certs=configuration.ssl_ca_cert,
cert_file=configuration.cert_file,
key_file=configuration.key_file,
**addition_pool_args
)
self.pool_manager = urllib3.PoolManager(**pool_args)
def request(
self,