Skip to content

Automatically add many type hints, with ruff #3222

New issue

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

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

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docker/api/build.py
Original file line number Diff line number Diff line change
@@ -322,7 +322,7 @@ def prune_builds(self, filters=None, keep_storage=None, all=None):
params['all'] = all
return self._result(self._post(url, params=params), True)

def _set_auth_headers(self, headers):
def _set_auth_headers(self, headers) -> None:
log.debug('Looking for auth config')

# If we don't have any auth data so far, try reloading the config
12 changes: 6 additions & 6 deletions docker/api/client.py
Original file line number Diff line number Diff line change
@@ -106,7 +106,7 @@ def __init__(self, base_url=None, version=None,
timeout=DEFAULT_TIMEOUT_SECONDS, tls=False,
user_agent=DEFAULT_USER_AGENT, num_pools=None,
credstore_env=None, use_ssh_client=False,
max_pool_size=DEFAULT_MAX_POOL_SIZE):
max_pool_size=DEFAULT_MAX_POOL_SIZE) -> None:
super().__init__()

if tls and not base_url:
@@ -243,7 +243,7 @@ def _put(self, url, **kwargs):
def _delete(self, url, **kwargs):
return self.delete(url, **self._set_request_timeout(kwargs))

def _url(self, pathfmt, *args, **kwargs):
def _url(self, pathfmt, *args, **kwargs) -> str:
for arg in args:
if not isinstance(arg, str):
raise ValueError(
@@ -259,7 +259,7 @@ def _url(self, pathfmt, *args, **kwargs):
else:
return f'{self.base_url}{formatted_path}'

def _raise_for_status(self, response):
def _raise_for_status(self, response) -> None:
"""Raises stored :class:`APIError`, if one occurred."""
try:
response.raise_for_status()
@@ -436,7 +436,7 @@ def _read_from_socket(self, response, stream, tty=True, demux=False):
finally:
response.close()

def _disable_socket_timeout(self, socket):
def _disable_socket_timeout(self, socket) -> None:
""" Depending on the combination of python version and whether we're
connecting over http or https, we might need to access _sock, which
may or may not exist; or we may need to just settimeout on socket
@@ -488,7 +488,7 @@ def _get_result_tty(self, stream, res, is_tty):
list(self._multiplexed_buffer_helper(res))
)

def _unmount(self, *args):
def _unmount(self, *args) -> None:
for proto in args:
self.adapters.pop(proto)

@@ -505,7 +505,7 @@ def get_adapter(self, url):
def api_version(self):
return self._version

def reload_config(self, dockercfg_path=None):
def reload_config(self, dockercfg_path=None) -> None:
"""
Force a reload of the auth configuration
2 changes: 1 addition & 1 deletion docker/api/config.py
Original file line number Diff line number Diff line change
@@ -56,7 +56,7 @@ def inspect_config(self, id):

@utils.minimum_version('1.30')
@utils.check_resource('id')
def remove_config(self, id):
def remove_config(self, id) -> bool:
"""
Remove a config
18 changes: 9 additions & 9 deletions docker/api/container.py
Original file line number Diff line number Diff line change
@@ -794,7 +794,7 @@ def inspect_container(self, container):
)

@utils.check_resource('container')
def kill(self, container, signal=None):
def kill(self, container, signal=None) -> None:
"""
Kill a container or send a signal to a container.
@@ -900,7 +900,7 @@ def logs(self, container, stdout=True, stderr=True, stream=False,
return output

@utils.check_resource('container')
def pause(self, container):
def pause(self, container) -> None:
"""
Pauses all processes within a container.
@@ -1013,7 +1013,7 @@ def prune_containers(self, filters=None):
return self._result(self._post(url, params=params), True)

@utils.check_resource('container')
def remove_container(self, container, v=False, link=False, force=False):
def remove_container(self, container, v=False, link=False, force=False) -> None:
"""
Remove a container. Similar to the ``docker rm`` command.
@@ -1036,7 +1036,7 @@ def remove_container(self, container, v=False, link=False, force=False):
self._raise_for_status(res)

@utils.check_resource('container')
def rename(self, container, name):
def rename(self, container, name) -> None:
"""
Rename a container. Similar to the ``docker rename`` command.
@@ -1054,7 +1054,7 @@ def rename(self, container, name):
self._raise_for_status(res)

@utils.check_resource('container')
def resize(self, container, height, width):
def resize(self, container, height, width) -> None:
"""
Resize the tty session.
@@ -1073,7 +1073,7 @@ def resize(self, container, height, width):
self._raise_for_status(res)

@utils.check_resource('container')
def restart(self, container, timeout=10):
def restart(self, container, timeout=10) -> None:
"""
Restart a container. Similar to the ``docker restart`` command.
@@ -1097,7 +1097,7 @@ def restart(self, container, timeout=10):
self._raise_for_status(res)

@utils.check_resource('container')
def start(self, container, *args, **kwargs):
def start(self, container, *args, **kwargs) -> None:
"""
Start a container. Similar to the ``docker start`` command, but
doesn't support attach options.
@@ -1183,7 +1183,7 @@ def stats(self, container, decode=None, stream=True, one_shot=None):
return self._result(self._get(url, params=params), json=True)

@utils.check_resource('container')
def stop(self, container, timeout=None):
def stop(self, container, timeout=None) -> None:
"""
Stops a container. Similar to the ``docker stop`` command.
@@ -1233,7 +1233,7 @@ def top(self, container, ps_args=None):
return self._result(self._get(u, params=params), True)

@utils.check_resource('container')
def unpause(self, container):
def unpause(self, container) -> None:
"""
Unpause all processes within a container.
2 changes: 1 addition & 1 deletion docker/api/exec_api.py
Original file line number Diff line number Diff line change
@@ -97,7 +97,7 @@ def exec_inspect(self, exec_id):
res = self._get(self._url("/exec/{0}/json", exec_id))
return self._result(res, True)

def exec_resize(self, exec_id, height=None, width=None):
def exec_resize(self, exec_id, height=None, width=None) -> None:
"""
Resize the tty session used by the specified exec command.
6 changes: 3 additions & 3 deletions docker/api/network.py
Original file line number Diff line number Diff line change
@@ -175,7 +175,7 @@ def prune_networks(self, filters=None):
return self._result(self._post(url, params=params), True)

@check_resource('net_id')
def remove_network(self, net_id):
def remove_network(self, net_id) -> None:
"""
Remove a network. Similar to the ``docker network rm`` command.
@@ -217,7 +217,7 @@ def connect_container_to_network(self, container, net_id,
ipv4_address=None, ipv6_address=None,
aliases=None, links=None,
link_local_ips=None, driver_opt=None,
mac_address=None):
mac_address=None) -> None:
"""
Connect a container to a network.
@@ -255,7 +255,7 @@ def connect_container_to_network(self, container, net_id,

@check_resource('container')
def disconnect_container_from_network(self, container, net_id,
force=False):
force=False) -> None:
"""
Disconnect a container from a network.
10 changes: 5 additions & 5 deletions docker/api/plugin.py
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
class PluginApiMixin:
@utils.minimum_version('1.25')
@utils.check_resource('name')
def configure_plugin(self, name, options):
def configure_plugin(self, name, options) -> bool:
"""
Configure a plugin.
@@ -25,7 +25,7 @@ def configure_plugin(self, name, options):
return True

@utils.minimum_version('1.25')
def create_plugin(self, name, plugin_data_dir, gzip=False):
def create_plugin(self, name, plugin_data_dir, gzip=False) -> bool:
"""
Create a new plugin.
@@ -51,7 +51,7 @@ def create_plugin(self, name, plugin_data_dir, gzip=False):
return True

@utils.minimum_version('1.25')
def disable_plugin(self, name, force=False):
def disable_plugin(self, name, force=False) -> bool:
"""
Disable an installed plugin.
@@ -69,7 +69,7 @@ def disable_plugin(self, name, force=False):
return True

@utils.minimum_version('1.25')
def enable_plugin(self, name, timeout=0):
def enable_plugin(self, name, timeout=0) -> bool:
"""
Enable an installed plugin.
@@ -206,7 +206,7 @@ def push_plugin(self, name):

@utils.minimum_version('1.25')
@utils.check_resource('name')
def remove_plugin(self, name, force=False):
def remove_plugin(self, name, force=False) -> bool:
"""
Remove an installed plugin.
2 changes: 1 addition & 1 deletion docker/api/secret.py
Original file line number Diff line number Diff line change
@@ -63,7 +63,7 @@ def inspect_secret(self, id):

@utils.minimum_version('1.25')
@utils.check_resource('id')
def remove_secret(self, id):
def remove_secret(self, id) -> bool:
"""
Remove a secret
6 changes: 3 additions & 3 deletions docker/api/service.py
Original file line number Diff line number Diff line change
@@ -3,9 +3,9 @@


def _check_api_features(version, task_template, update_config, endpoint_spec,
rollback_config):
rollback_config) -> None:

def raise_version_error(param, min_version):
def raise_version_error(param, min_version) -> None:
raise errors.InvalidVersion(
f'{param} is not supported in API version < {min_version}'
)
@@ -239,7 +239,7 @@ def inspect_task(self, task):

@utils.minimum_version('1.24')
@utils.check_resource('service')
def remove_service(self, service):
def remove_service(self, service) -> bool:
"""
Stop and remove a service.
12 changes: 6 additions & 6 deletions docker/api/swarm.py
Original file line number Diff line number Diff line change
@@ -216,7 +216,7 @@ def inspect_node(self, node_id):

@utils.minimum_version('1.24')
def join_swarm(self, remote_addrs, join_token, listen_addr='0.0.0.0:2377',
advertise_addr=None, data_path_addr=None):
advertise_addr=None, data_path_addr=None) -> bool:
"""
Make this Engine join a swarm that has already been created.
@@ -266,7 +266,7 @@ def join_swarm(self, remote_addrs, join_token, listen_addr='0.0.0.0:2377',
return True

@utils.minimum_version('1.24')
def leave_swarm(self, force=False):
def leave_swarm(self, force=False) -> bool:
"""
Leave a swarm.
@@ -319,7 +319,7 @@ def nodes(self, filters=None):

@utils.check_resource('node_id')
@utils.minimum_version('1.24')
def remove_node(self, node_id, force=False):
def remove_node(self, node_id, force=False) -> bool:
"""
Remove a node from the swarm.
@@ -345,7 +345,7 @@ def remove_node(self, node_id, force=False):
return True

@utils.minimum_version('1.24')
def unlock_swarm(self, key):
def unlock_swarm(self, key) -> bool:
"""
Unlock a locked swarm.
@@ -381,7 +381,7 @@ def unlock_swarm(self, key):
return True

@utils.minimum_version('1.24')
def update_node(self, node_id, version, node_spec=None):
def update_node(self, node_id, version, node_spec=None) -> bool:
"""
Update the node's configuration
@@ -420,7 +420,7 @@ def update_node(self, node_id, version, node_spec=None):
def update_swarm(self, version, swarm_spec=None,
rotate_worker_token=False,
rotate_manager_token=False,
rotate_manager_unlock_key=False):
rotate_manager_unlock_key=False) -> bool:
"""
Update the Swarm's configuration
2 changes: 1 addition & 1 deletion docker/api/volume.py
Original file line number Diff line number Diff line change
@@ -138,7 +138,7 @@ def prune_volumes(self, filters=None):
url = self._url('/volumes/prune')
return self._result(self._post(url, params=params), True)

def remove_volume(self, name, force=False):
def remove_volume(self, name, force=False) -> None:
"""
Remove a volume. Similar to the ``docker volume rm`` command.
6 changes: 3 additions & 3 deletions docker/auth.py
Original file line number Diff line number Diff line change
@@ -74,7 +74,7 @@ def get_credential_store(authconfig, registry):


class AuthConfig(dict):
def __init__(self, dct, credstore_env=None):
def __init__(self, dct, credstore_env=None) -> None:
if 'auths' not in dct:
dct['auths'] = {}
self.update(dct)
@@ -202,7 +202,7 @@ def cred_helpers(self):
return self.get('credHelpers', {})

@property
def is_empty(self):
def is_empty(self) -> bool:
return (
not self.auths and not self.creds_store and not self.cred_helpers
)
@@ -303,7 +303,7 @@ def get_all_credentials(self):

return auth_data

def add_auth(self, reg, data):
def add_auth(self, reg, data) -> None:
self['auths'][reg] = data


2 changes: 1 addition & 1 deletion docker/client.py
Original file line number Diff line number Diff line change
@@ -41,7 +41,7 @@ class DockerClient:
max_pool_size (int): The maximum number of connections
to save in the pool.
"""
def __init__(self, *args, **kwargs):
def __init__(self, *args, **kwargs) -> None:
self.api = APIClient(*args, **kwargs)

@classmethod
4 changes: 2 additions & 2 deletions docker/context/api.py
Original file line number Diff line number Diff line change
@@ -130,7 +130,7 @@ def get_current_context(cls):
return cls.get_context()

@classmethod
def set_current_context(cls, name="default"):
def set_current_context(cls, name="default") -> None:
ctx = cls.get_context(name)
if not ctx:
raise errors.ContextNotFound(name)
@@ -141,7 +141,7 @@ def set_current_context(cls, name="default"):
f'Failed to set current context: {err}')

@classmethod
def remove_context(cls, name):
def remove_context(cls, name) -> None:
"""Remove a context. Similar to the ``docker context rm`` command.
Args:
14 changes: 7 additions & 7 deletions docker/context/context.py
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ class Context:
"""A context."""

def __init__(self, name, orchestrator=None, host=None, endpoints=None,
tls=False):
tls=False) -> None:
if not name:
raise Exception("Name not provided")
self.name = name
@@ -57,7 +57,7 @@ def __init__(self, name, orchestrator=None, host=None, endpoints=None,

def set_endpoint(
self, name="docker", host=None, tls_cfg=None,
skip_tls_verify=False, def_namespace=None):
skip_tls_verify=False, def_namespace=None) -> None:
self.endpoints[name] = {
"Host": get_context_host(host, not skip_tls_verify),
"SkipTLSVerify": skip_tls_verify
@@ -113,7 +113,7 @@ def _load_meta(cls, name):

return metadata

def _load_certs(self):
def _load_certs(self) -> None:
certs = {}
tls_dir = get_tls_dir(self.name)
for endpoint in self.endpoints.keys():
@@ -139,7 +139,7 @@ def _load_certs(self):
self.tls_cfg = certs
self.tls_path = tls_dir

def save(self):
def save(self) -> None:
meta_dir = get_meta_dir(self.name)
if not os.path.isdir(meta_dir):
os.makedirs(meta_dir)
@@ -166,16 +166,16 @@ def save(self):
self.meta_path = get_meta_dir(self.name)
self.tls_path = get_tls_dir(self.name)

def remove(self):
def remove(self) -> None:
if os.path.isdir(self.meta_path):
rmtree(self.meta_path)
if os.path.isdir(self.tls_path):
rmtree(self.tls_path)

def __repr__(self):
def __repr__(self) -> str:
return f"<{self.__class__.__name__}: '{self.name}'>"

def __str__(self):
def __str__(self) -> str:
return json.dumps(self.__call__(), indent=2)

def __call__(self):
4 changes: 2 additions & 2 deletions docker/credentials/store.py
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@


class Store:
def __init__(self, program, environment=None):
def __init__(self, program, environment=None) -> None:
""" Create a store object that acts as an interface to
perform the basic operations for storing, retrieving
and erasing credentials using `program`.
@@ -55,7 +55,7 @@ def store(self, server, username, secret):
}).encode('utf-8')
return self._execute('store', data_input)

def erase(self, server):
def erase(self, server) -> None:
""" Erase credentials for `server`. Raises a `StoreError` if an error
occurs.
"""
32 changes: 16 additions & 16 deletions docker/errors.py
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ class DockerException(Exception):
"""


def create_api_error_from_http_exception(e):
def create_api_error_from_http_exception(e) -> None:
"""
Create a suitable APIError from requests.exceptions.HTTPError.
"""
@@ -43,14 +43,14 @@ class APIError(requests.exceptions.HTTPError, DockerException):
"""
An HTTP error from the API.
"""
def __init__(self, message, response=None, explanation=None):
def __init__(self, message, response=None, explanation=None) -> None:
# requests 1.2 supports response as a keyword argument, but
# requests 1.1 doesn't
super().__init__(message)
self.response = response
self.explanation = explanation

def __str__(self):
def __str__(self) -> str:
message = super().__str__()

if self.is_client_error():
@@ -118,10 +118,10 @@ class DeprecatedMethod(DockerException):


class TLSParameterError(DockerException):
def __init__(self, msg):
def __init__(self, msg) -> None:
self.msg = msg

def __str__(self):
def __str__(self) -> str:
return self.msg + (". TLS configurations should map the Docker CLI "
"client configurations. See "
"https://docs.docker.com/engine/articles/https/ "
@@ -136,7 +136,7 @@ class ContainerError(DockerException):
"""
Represents a container that has exited with a non-zero exit code.
"""
def __init__(self, container, exit_status, command, image, stderr):
def __init__(self, container, exit_status, command, image, stderr) -> None:
self.container = container
self.exit_status = exit_status
self.command = command
@@ -151,12 +151,12 @@ def __init__(self, container, exit_status, command, image, stderr):


class StreamParseError(RuntimeError):
def __init__(self, reason):
def __init__(self, reason) -> None:
self.msg = reason


class BuildError(DockerException):
def __init__(self, reason, build_log):
def __init__(self, reason, build_log) -> None:
super().__init__(reason)
self.msg = reason
self.build_log = build_log
@@ -178,32 +178,32 @@ def create_unexpected_kwargs_error(name, kwargs):


class MissingContextParameter(DockerException):
def __init__(self, param):
def __init__(self, param) -> None:
self.param = param

def __str__(self):
def __str__(self) -> str:
return (f"missing parameter: {self.param}")


class ContextAlreadyExists(DockerException):
def __init__(self, name):
def __init__(self, name) -> None:
self.name = name

def __str__(self):
def __str__(self) -> str:
return (f"context {self.name} already exists")


class ContextException(DockerException):
def __init__(self, msg):
def __init__(self, msg) -> None:
self.msg = msg

def __str__(self):
def __str__(self) -> str:
return (self.msg)


class ContextNotFound(DockerException):
def __init__(self, name):
def __init__(self, name) -> None:
self.name = name

def __str__(self):
def __str__(self) -> str:
return (f"context '{self.name}' not found")
2 changes: 1 addition & 1 deletion docker/models/configs.py
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ class Config(Model):
"""A config."""
id_attribute = 'ID'

def __repr__(self):
def __repr__(self) -> str:
return f"<{self.__class__.__name__}: '{self.name}'>"

@property
8 changes: 4 additions & 4 deletions docker/models/images.py
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ class Image(Model):
"""
An image on the server.
"""
def __repr__(self):
def __repr__(self) -> str:
tag_str = "', '".join(self.tags)
return f"<{self.__class__.__name__}: '{tag_str}'>"

@@ -143,7 +143,7 @@ class RegistryData(Model):
"""
Image metadata stored on the registry, including available platforms.
"""
def __init__(self, image_name, *args, **kwargs):
def __init__(self, image_name, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
self.image_name = image_name

@@ -208,7 +208,7 @@ def has_platform(self, platform):
platform, self.client.version()
) in self.attrs['Platforms']

def reload(self):
def reload(self) -> None:
self.attrs = self.client.api.inspect_distribution(self.image_name)

reload.__doc__ = Model.reload.__doc__
@@ -478,7 +478,7 @@ def push(self, repository, tag=None, **kwargs):
return self.client.api.push(repository, tag=tag, **kwargs)
push.__doc__ = APIClient.push.__doc__

def remove(self, *args, **kwargs):
def remove(self, *args, **kwargs) -> None:
self.client.api.remove_image(*args, **kwargs)
remove.__doc__ = APIClient.remove_image.__doc__

8 changes: 4 additions & 4 deletions docker/models/plugins.py
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ class Plugin(Model):
"""
A plugin on the server.
"""
def __repr__(self):
def __repr__(self) -> str:
return f"<{self.__class__.__name__}: '{self.name}'>"

@property
@@ -30,7 +30,7 @@ def settings(self):
"""
return self.attrs.get('Settings')

def configure(self, options):
def configure(self, options) -> None:
"""
Update the plugin's settings.
@@ -44,7 +44,7 @@ def configure(self, options):
self.client.api.configure_plugin(self.name, options)
self.reload()

def disable(self, force=False):
def disable(self, force=False) -> None:
"""
Disable the plugin.
@@ -59,7 +59,7 @@ def disable(self, force=False):
self.client.api.disable_plugin(self.name, force)
self.reload()

def enable(self, timeout=0):
def enable(self, timeout=0) -> None:
"""
Enable the plugin.
14 changes: 7 additions & 7 deletions docker/models/resource.py
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ class Model:
"""
id_attribute = 'Id'

def __init__(self, attrs=None, client=None, collection=None):
def __init__(self, attrs=None, client=None, collection=None) -> None:
#: A client pointing at the server that this object is on.
self.client = client

@@ -16,7 +16,7 @@ def __init__(self, attrs=None, client=None, collection=None):
if self.attrs is None:
self.attrs = {}

def __repr__(self):
def __repr__(self) -> str:
return f"<{self.__class__.__name__}: {self.short_id}>"

def __eq__(self, other):
@@ -39,7 +39,7 @@ def short_id(self):
"""
return self.id[:12]

def reload(self):
def reload(self) -> None:
"""
Load this object from the server again and update ``attrs`` with the
new data.
@@ -57,7 +57,7 @@ class Collection:
#: The type of object this collection represents, set by subclasses
model = None

def __init__(self, client=None):
def __init__(self, client=None) -> None:
#: The client pointing at the server that this collection of objects
#: is on.
self.client = client
@@ -69,13 +69,13 @@ def __call__(self, *args, **kwargs):
"use docker.APIClient if so."
)

def list(self):
def list(self) -> None:
raise NotImplementedError

def get(self, key):
def get(self, key) -> None:
raise NotImplementedError

def create(self, attrs=None):
def create(self, attrs=None) -> None:
raise NotImplementedError

def prepare_model(self, attrs):
2 changes: 1 addition & 1 deletion docker/models/secrets.py
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ class Secret(Model):
"""A secret."""
id_attribute = 'ID'

def __repr__(self):
def __repr__(self) -> str:
return f"<{self.__class__.__name__}: '{self.name}'>"

@property
4 changes: 2 additions & 2 deletions docker/models/swarm.py
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ class Swarm(Model):
"""
id_attribute = 'ID'

def __init__(self, *args, **kwargs):
def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
if self.client:
try:
@@ -140,7 +140,7 @@ def leave(self, *args, **kwargs):
return self.client.api.leave_swarm(*args, **kwargs)
leave.__doc__ = APIClient.leave_swarm.__doc__

def reload(self):
def reload(self) -> None:
"""
Inspect the swarm on the server and store the response in
:py:attr:`attrs`.
4 changes: 2 additions & 2 deletions docker/tls.py
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ class TLSConfig:
ca_cert = None
verify = None

def __init__(self, client_cert=None, ca_cert=None, verify=None):
def __init__(self, client_cert=None, ca_cert=None, verify=None) -> None:
# Argument compatibility/mapping with
# https://docs.docker.com/engine/articles/https/
# This diverges from the Docker CLI in that users can specify 'tls'
@@ -54,7 +54,7 @@ def __init__(self, client_cert=None, ca_cert=None, verify=None):
'Invalid CA certificate provided for `ca_cert`.'
)

def configure_client(self, client):
def configure_client(self, client) -> None:
"""
Configure a client with these TLS options.
"""
2 changes: 1 addition & 1 deletion docker/transport/basehttpadapter.py
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@


class BaseHTTPAdapter(requests.adapters.HTTPAdapter):
def close(self):
def close(self) -> None:
super().close()
if hasattr(self, 'pools'):
self.pools.clear()
8 changes: 4 additions & 4 deletions docker/transport/npipeconn.py
Original file line number Diff line number Diff line change
@@ -12,22 +12,22 @@


class NpipeHTTPConnection(urllib3.connection.HTTPConnection):
def __init__(self, npipe_path, timeout=60):
def __init__(self, npipe_path, timeout=60) -> None:
super().__init__(
'localhost', timeout=timeout
)
self.npipe_path = npipe_path
self.timeout = timeout

def connect(self):
def connect(self) -> None:
sock = NpipeSocket()
sock.settimeout(self.timeout)
sock.connect(self.npipe_path)
self.sock = sock


class NpipeHTTPConnectionPool(urllib3.connectionpool.HTTPConnectionPool):
def __init__(self, npipe_path, timeout=60, maxsize=10):
def __init__(self, npipe_path, timeout=60, maxsize=10) -> None:
super().__init__(
'localhost', timeout=timeout, maxsize=maxsize
)
@@ -70,7 +70,7 @@ class NpipeHTTPAdapter(BaseHTTPAdapter):

def __init__(self, base_url, timeout=60,
pool_connections=constants.DEFAULT_NUM_POOLS,
max_pool_size=constants.DEFAULT_MAX_POOL_SIZE):
max_pool_size=constants.DEFAULT_MAX_POOL_SIZE) -> None:
self.npipe_path = base_url.replace('npipe://', '')
self.timeout = timeout
self.max_pool_size = max_pool_size
30 changes: 15 additions & 15 deletions docker/transport/npipesocket.py
Original file line number Diff line number Diff line change
@@ -33,18 +33,18 @@ class NpipeSocket:
implemented.
"""

def __init__(self, handle=None):
def __init__(self, handle=None) -> None:
self._timeout = win32pipe.NMPWAIT_USE_DEFAULT_WAIT
self._handle = handle
self._closed = False

def accept(self):
def accept(self) -> None:
raise NotImplementedError()

def bind(self, address):
def bind(self, address) -> None:
raise NotImplementedError()

def close(self):
def close(self) -> None:
self._handle.Close()
self._closed = True

@@ -99,13 +99,13 @@ def getpeername(self):
def getsockname(self):
return self._address

def getsockopt(self, level, optname, buflen=None):
def getsockopt(self, level, optname, buflen=None) -> None:
raise NotImplementedError()

def ioctl(self, control, option):
def ioctl(self, control, option) -> None:
raise NotImplementedError()

def listen(self, backlog):
def listen(self, backlog) -> None:
raise NotImplementedError()

def makefile(self, mode=None, bufsize=None):
@@ -182,7 +182,7 @@ def setblocking(self, flag):
return self.settimeout(None)
return self.settimeout(0)

def settimeout(self, value):
def settimeout(self, value) -> None:
if value is None:
# Blocking mode
self._timeout = win32event.INFINITE
@@ -195,7 +195,7 @@ def settimeout(self, value):
def gettimeout(self):
return self._timeout

def setsockopt(self, level, optname, value):
def setsockopt(self, level, optname, value) -> None:
raise NotImplementedError()

@check_closed
@@ -204,27 +204,27 @@ def shutdown(self, how):


class NpipeFileIOBase(io.RawIOBase):
def __init__(self, npipe_socket):
def __init__(self, npipe_socket) -> None:
self.sock = npipe_socket

def close(self):
def close(self) -> None:
super().close()
self.sock = None

def fileno(self):
return self.sock.fileno()

def isatty(self):
def isatty(self) -> bool:
return False

def readable(self):
def readable(self) -> bool:
return True

def readinto(self, buf):
return self.sock.recv_into(buf)

def seekable(self):
def seekable(self) -> bool:
return False

def writable(self):
def writable(self) -> bool:
return False
24 changes: 12 additions & 12 deletions docker/transport/sshconn.py
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@


class SSHSocket(socket.socket):
def __init__(self, host):
def __init__(self, host) -> None:
super().__init__(
socket.AF_INET, socket.SOCK_STREAM)
self.host = host
@@ -31,7 +31,7 @@ def __init__(self, host):

self.proc = None

def connect(self, **kwargs):
def connect(self, **kwargs) -> None:
args = ['ssh']
if self.user:
args = args + ['-l', self.user]
@@ -43,7 +43,7 @@ def connect(self, **kwargs):

preexec_func = None
if not constants.IS_WINDOWS_PLATFORM:
def f():
def f() -> None:
signal.signal(signal.SIGINT, signal.SIG_IGN)
preexec_func = f

@@ -68,7 +68,7 @@ def _write(self, data):
self.proc.stdin.flush()
return written

def sendall(self, data):
def sendall(self, data) -> None:
self._write(data)

def send(self, data):
@@ -87,7 +87,7 @@ def makefile(self, mode):

return self.proc.stdout

def close(self):
def close(self) -> None:
if not self.proc or self.proc.stdin.closed:
return
self.proc.stdin.write(b'\n\n')
@@ -96,15 +96,15 @@ def close(self):


class SSHConnection(urllib3.connection.HTTPConnection):
def __init__(self, ssh_transport=None, timeout=60, host=None):
def __init__(self, ssh_transport=None, timeout=60, host=None) -> None:
super().__init__(
'localhost', timeout=timeout
)
self.ssh_transport = ssh_transport
self.timeout = timeout
self.ssh_host = host

def connect(self):
def connect(self) -> None:
if self.ssh_transport:
sock = self.ssh_transport.open_session()
sock.settimeout(self.timeout)
@@ -120,7 +120,7 @@ def connect(self):
class SSHConnectionPool(urllib3.connectionpool.HTTPConnectionPool):
scheme = 'ssh'

def __init__(self, ssh_client=None, timeout=60, maxsize=10, host=None):
def __init__(self, ssh_client=None, timeout=60, maxsize=10, host=None) -> None:
super().__init__(
'localhost', timeout=timeout, maxsize=maxsize
)
@@ -165,7 +165,7 @@ class SSHHTTPAdapter(BaseHTTPAdapter):
def __init__(self, base_url, timeout=60,
pool_connections=constants.DEFAULT_NUM_POOLS,
max_pool_size=constants.DEFAULT_MAX_POOL_SIZE,
shell_out=False):
shell_out=False) -> None:
self.ssh_client = None
if not shell_out:
self._create_paramiko_client(base_url)
@@ -182,7 +182,7 @@ def __init__(self, base_url, timeout=60,
)
super().__init__()

def _create_paramiko_client(self, base_url):
def _create_paramiko_client(self, base_url) -> None:
logging.getLogger("paramiko").setLevel(logging.WARNING)
self.ssh_client = paramiko.SSHClient()
base_url = urllib.parse.urlparse(base_url)
@@ -213,7 +213,7 @@ def _create_paramiko_client(self, base_url):
self.ssh_client.load_system_host_keys()
self.ssh_client.set_missing_host_key_policy(paramiko.RejectPolicy())

def _connect(self):
def _connect(self) -> None:
if self.ssh_client:
self.ssh_client.connect(**self.ssh_params)

@@ -244,7 +244,7 @@ def get_connection(self, url, proxies=None):

return pool

def close(self):
def close(self) -> None:
super().close()
if self.ssh_client:
self.ssh_client.close()
8 changes: 4 additions & 4 deletions docker/transport/unixconn.py
Original file line number Diff line number Diff line change
@@ -13,23 +13,23 @@

class UnixHTTPConnection(urllib3.connection.HTTPConnection):

def __init__(self, base_url, unix_socket, timeout=60):
def __init__(self, base_url, unix_socket, timeout=60) -> None:
super().__init__(
'localhost', timeout=timeout
)
self.base_url = base_url
self.unix_socket = unix_socket
self.timeout = timeout

def connect(self):
def connect(self) -> None:
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
sock.settimeout(self.timeout)
sock.connect(self.unix_socket)
self.sock = sock


class UnixHTTPConnectionPool(urllib3.connectionpool.HTTPConnectionPool):
def __init__(self, base_url, socket_path, timeout=60, maxsize=10):
def __init__(self, base_url, socket_path, timeout=60, maxsize=10) -> None:
super().__init__(
'localhost', timeout=timeout, maxsize=maxsize
)
@@ -52,7 +52,7 @@ class UnixHTTPAdapter(BaseHTTPAdapter):

def __init__(self, socket_url, timeout=60,
pool_connections=constants.DEFAULT_NUM_POOLS,
max_pool_size=constants.DEFAULT_MAX_POOL_SIZE):
max_pool_size=constants.DEFAULT_MAX_POOL_SIZE) -> None:
socket_path = socket_url.replace('http+unix://', '')
if not socket_path.startswith('/'):
socket_path = f"/{socket_path}"
2 changes: 1 addition & 1 deletion docker/types/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class DictType(dict):
def __init__(self, init):
def __init__(self, init) -> None:
for k, v in init.items():
self[k] = v
32 changes: 16 additions & 16 deletions docker/types/containers.py
Original file line number Diff line number Diff line change
@@ -55,7 +55,7 @@ class LogConfig(DictType):
"""
types = LogConfigTypesEnum

def __init__(self, **kwargs):
def __init__(self, **kwargs) -> None:
log_driver_type = kwargs.get('type', kwargs.get('Type'))
config = kwargs.get('config', kwargs.get('Config')) or {}

@@ -72,20 +72,20 @@ def type(self):
return self['Type']

@type.setter
def type(self, value):
def type(self, value) -> None:
self['Type'] = value

@property
def config(self):
return self['Config']

def set_config_value(self, key, value):
def set_config_value(self, key, value) -> None:
""" Set a the value for ``key`` to ``value`` inside the ``config``
dict.
"""
self.config[key] = value

def unset_config(self, key):
def unset_config(self, key) -> None:
""" Remove the ``key`` property from the ``config`` dict. """
if key in self.config:
del self.config[key]
@@ -114,7 +114,7 @@ class Ulimit(DictType):
[{'Name': 'nproc', 'Hard': 0, 'Soft': 1024}]
"""
def __init__(self, **kwargs):
def __init__(self, **kwargs) -> None:
name = kwargs.get('name', kwargs.get('Name'))
soft = kwargs.get('soft', kwargs.get('Soft'))
hard = kwargs.get('hard', kwargs.get('Hard'))
@@ -135,23 +135,23 @@ def name(self):
return self['Name']

@name.setter
def name(self, value):
def name(self, value) -> None:
self['Name'] = value

@property
def soft(self):
return self.get('Soft')

@soft.setter
def soft(self, value):
def soft(self, value) -> None:
self['Soft'] = value

@property
def hard(self):
return self.get('Hard')

@hard.setter
def hard(self, value):
def hard(self, value) -> None:
self['Hard'] = value


@@ -176,7 +176,7 @@ class DeviceRequest(DictType):
options (dict): Driver-specific options. Optional.
"""

def __init__(self, **kwargs):
def __init__(self, **kwargs) -> None:
driver = kwargs.get('driver', kwargs.get('Driver'))
count = kwargs.get('count', kwargs.get('Count'))
device_ids = kwargs.get('device_ids', kwargs.get('DeviceIDs'))
@@ -217,39 +217,39 @@ def driver(self):
return self['Driver']

@driver.setter
def driver(self, value):
def driver(self, value) -> None:
self['Driver'] = value

@property
def count(self):
return self['Count']

@count.setter
def count(self, value):
def count(self, value) -> None:
self['Count'] = value

@property
def device_ids(self):
return self['DeviceIDs']

@device_ids.setter
def device_ids(self, value):
def device_ids(self, value) -> None:
self['DeviceIDs'] = value

@property
def capabilities(self):
return self['Capabilities']

@capabilities.setter
def capabilities(self, value):
def capabilities(self, value) -> None:
self['Capabilities'] = value

@property
def options(self):
return self['Options']

@options.setter
def options(self, value):
def options(self, value) -> None:
self['Options'] = value


@@ -276,7 +276,7 @@ def __init__(self, version, binds=None, port_bindings=None,
nano_cpus=None, cpuset_mems=None, runtime=None, mounts=None,
cpu_rt_period=None, cpu_rt_runtime=None,
device_cgroup_rules=None, device_requests=None,
cgroupns=None):
cgroupns=None) -> None:

if mem_limit is not None:
self['Memory'] = parse_bytes(mem_limit)
@@ -685,7 +685,7 @@ def __init__(
working_dir=None, domainname=None, host_config=None, mac_address=None,
labels=None, stop_signal=None, networking_config=None,
healthcheck=None, stop_timeout=None, runtime=None
):
) -> None:

if stop_timeout is not None and version_lt(version, '1.25'):
raise errors.InvalidVersion(
4 changes: 2 additions & 2 deletions docker/types/daemon.py
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ class CancellableStream:
>>> events.close()
"""

def __init__(self, stream, response):
def __init__(self, stream, response) -> None:
self._stream = stream
self._response = response

@@ -34,7 +34,7 @@ def __next__(self):

next = __next__

def close(self):
def close(self) -> None:
"""
Closes the event streaming.
"""
12 changes: 6 additions & 6 deletions docker/types/healthcheck.py
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ class Healthcheck(DictType):
initialize before starting health-retries countdown in
nanoseconds. It should be 0 or at least 1000000 (1 ms).
"""
def __init__(self, **kwargs):
def __init__(self, **kwargs) -> None:
test = kwargs.get('test', kwargs.get('Test'))
if isinstance(test, str):
test = ["CMD-SHELL", test]
@@ -50,7 +50,7 @@ def test(self):
return self['Test']

@test.setter
def test(self, value):
def test(self, value) -> None:
if isinstance(value, str):
value = ["CMD-SHELL", value]
self['Test'] = value
@@ -60,29 +60,29 @@ def interval(self):
return self['Interval']

@interval.setter
def interval(self, value):
def interval(self, value) -> None:
self['Interval'] = value

@property
def timeout(self):
return self['Timeout']

@timeout.setter
def timeout(self, value):
def timeout(self, value) -> None:
self['Timeout'] = value

@property
def retries(self):
return self['Retries']

@retries.setter
def retries(self, value):
def retries(self, value) -> None:
self['Retries'] = value

@property
def start_period(self):
return self['StartPeriod']

@start_period.setter
def start_period(self, value):
def start_period(self, value) -> None:
self['StartPeriod'] = value
8 changes: 4 additions & 4 deletions docker/types/networks.py
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
class EndpointConfig(dict):
def __init__(self, version, aliases=None, links=None, ipv4_address=None,
ipv6_address=None, link_local_ips=None, driver_opt=None,
mac_address=None):
mac_address=None) -> None:
if version_lt(version, '1.22'):
raise errors.InvalidVersion(
'Endpoint config is not supported for API version < 1.22'
@@ -52,7 +52,7 @@ def __init__(self, version, aliases=None, links=None, ipv4_address=None,


class NetworkingConfig(dict):
def __init__(self, endpoints_config=None):
def __init__(self, endpoints_config=None) -> None:
if endpoints_config:
self["EndpointsConfig"] = endpoints_config

@@ -76,7 +76,7 @@ class IPAMConfig(dict):
>>> network = client.create_network('network1', ipam=ipam_config)
"""
def __init__(self, driver='default', pool_configs=None, options=None):
def __init__(self, driver='default', pool_configs=None, options=None) -> None:
self.update({
'Driver': driver,
'Config': pool_configs or []
@@ -119,7 +119,7 @@ class IPAMPool(dict):
pool_configs=[ipam_pool])
"""
def __init__(self, subnet=None, iprange=None, gateway=None,
aux_addresses=None):
aux_addresses=None) -> None:
self.update({
'Subnet': subnet,
'IPRange': iprange,
32 changes: 16 additions & 16 deletions docker/types/services.py
Original file line number Diff line number Diff line change
@@ -32,7 +32,7 @@ class TaskTemplate(dict):

def __init__(self, container_spec, resources=None, restart_policy=None,
placement=None, log_driver=None, networks=None,
force_update=None):
force_update=None) -> None:
self['ContainerSpec'] = container_spec
if resources:
self['Resources'] = resources
@@ -125,7 +125,7 @@ def __init__(self, image, command=None, args=None, hostname=None, env=None,
open_stdin=None, read_only=None, stop_signal=None,
healthcheck=None, hosts=None, dns_config=None, configs=None,
privileges=None, isolation=None, init=None, cap_add=None,
cap_drop=None, sysctls=None):
cap_drop=None, sysctls=None) -> None:
self['Image'] = image

if isinstance(command, str):
@@ -245,7 +245,7 @@ class Mount(dict):
def __init__(self, target, source, type='volume', read_only=False,
consistency=None, propagation=None, no_copy=False,
labels=None, driver_config=None, tmpfs_size=None,
tmpfs_mode=None):
tmpfs_mode=None) -> None:
self['Target'] = target
self['Source'] = source
if type not in ('bind', 'volume', 'tmpfs', 'npipe'):
@@ -344,7 +344,7 @@ class Resources(dict):
"""

def __init__(self, cpu_limit=None, mem_limit=None, cpu_reservation=None,
mem_reservation=None, generic_resources=None):
mem_reservation=None, generic_resources=None) -> None:
limits = {}
reservation = {}
if cpu_limit is not None:
@@ -415,7 +415,7 @@ class UpdateConfig(dict):
"""

def __init__(self, parallelism=0, delay=None, failure_action='continue',
monitor=None, max_failure_ratio=None, order=None):
monitor=None, max_failure_ratio=None, order=None) -> None:
self['Parallelism'] = parallelism
if delay is not None:
self['Delay'] = delay
@@ -500,7 +500,7 @@ class RestartPolicy(dict):
condition_types = RestartConditionTypesEnum

def __init__(self, condition=RestartConditionTypesEnum.NONE, delay=0,
max_attempts=0, window=0):
max_attempts=0, window=0) -> None:
if condition not in self.condition_types._values:
raise TypeError(
f'Invalid RestartPolicy condition {condition}'
@@ -526,7 +526,7 @@ class DriverConfig(dict):
options (dict): Driver-specific options. Default: ``None``.
"""

def __init__(self, name, options=None):
def __init__(self, name, options=None) -> None:
self['Name'] = name
if options:
self['Options'] = options
@@ -548,7 +548,7 @@ class EndpointSpec(dict):
Ports can only be provided if the ``vip`` resolution mode is used.
"""

def __init__(self, mode=None, ports=None):
def __init__(self, mode=None, ports=None) -> None:
if ports:
self['Ports'] = convert_service_ports(ports)
if mode:
@@ -601,7 +601,7 @@ class ServiceMode(dict):
services only.
"""

def __init__(self, mode, replicas=None, concurrency=None):
def __init__(self, mode, replicas=None, concurrency=None) -> None:
replicated_modes = ('replicated', 'replicated-job')
supported_modes = replicated_modes + ('global', 'global-job')

@@ -673,7 +673,7 @@ class SecretReference(dict):
"""
@check_resource('secret_id')
def __init__(self, secret_id, secret_name, filename=None, uid=None,
gid=None, mode=0o444):
gid=None, mode=0o444) -> None:
self['SecretName'] = secret_name
self['SecretID'] = secret_id
self['File'] = {
@@ -701,7 +701,7 @@ class ConfigReference(dict):
"""
@check_resource('config_id')
def __init__(self, config_id, config_name, filename=None, uid=None,
gid=None, mode=0o444):
gid=None, mode=0o444) -> None:
self['ConfigName'] = config_name
self['ConfigID'] = config_id
self['File'] = {
@@ -729,7 +729,7 @@ class Placement(dict):
"""

def __init__(self, constraints=None, preferences=None, platforms=None,
maxreplicas=None):
maxreplicas=None) -> None:
if constraints is not None:
self['Constraints'] = constraints
if preferences is not None:
@@ -761,7 +761,7 @@ class PlacementPreference(dict):
nodes identified by this label.
"""

def __init__(self, strategy, descriptor):
def __init__(self, strategy, descriptor) -> None:
if strategy != 'spread':
raise errors.InvalidArgument(
f'PlacementPreference strategy value is invalid ({strategy}): '
@@ -783,7 +783,7 @@ class DNSConfig(dict):
to be modified (e.g., ``debug``, ``ndots:3``, etc.).
"""

def __init__(self, nameservers=None, search=None, options=None):
def __init__(self, nameservers=None, search=None, options=None) -> None:
self['Nameservers'] = nameservers
self['Search'] = search
self['Options'] = options
@@ -816,7 +816,7 @@ class Privileges(dict):

def __init__(self, credentialspec_file=None, credentialspec_registry=None,
selinux_disable=None, selinux_user=None, selinux_role=None,
selinux_type=None, selinux_level=None):
selinux_type=None, selinux_level=None) -> None:
credential_spec = {}
if credentialspec_registry is not None:
credential_spec['Registry'] = credentialspec_registry
@@ -857,7 +857,7 @@ class NetworkAttachmentConfig(dict):
network target.
"""

def __init__(self, target, aliases=None, options=None):
def __init__(self, target, aliases=None, options=None) -> None:
self['Target'] = target
self['Aliases'] = aliases
self['DriverOpts'] = options
4 changes: 2 additions & 2 deletions docker/types/swarm.py
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ def __init__(self, version, task_history_retention_limit=None,
node_cert_expiry=None, external_cas=None, name=None,
labels=None, signing_ca_cert=None, signing_ca_key=None,
ca_force_rotate=None, autolock_managers=None,
log_driver=None):
log_driver=None) -> None:
if task_history_retention_limit is not None:
self['Orchestration'] = {
'TaskHistoryRetentionLimit': task_history_retention_limit
@@ -112,7 +112,7 @@ class SwarmExternalCA(dict):
"""
def __init__(self, url, protocol=None, options=None, ca_cert=None):
def __init__(self, url, protocol=None, options=None, ca_cert=None) -> None:
self['URL'] = url
self['Protocol'] = protocol
self['Options'] = options
4 changes: 2 additions & 2 deletions docker/utils/build.py
Original file line number Diff line number Diff line change
@@ -158,7 +158,7 @@ def walk(root, patterns, default=True):
# Heavily based on
# https://github.com/moby/moby/blob/master/pkg/fileutils/fileutils.go
class PatternMatcher:
def __init__(self, patterns):
def __init__(self, patterns) -> None:
self.patterns = list(filter(
lambda p: p.dirs, [Pattern(p) for p in patterns]
))
@@ -221,7 +221,7 @@ def rec_walk(current_dir):


class Pattern:
def __init__(self, pattern_str):
def __init__(self, pattern_str) -> None:
self.exclusion = False
if pattern_str.startswith('!'):
self.exclusion = True
4 changes: 2 additions & 2 deletions docker/utils/fnmatch.py
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@
_MAXCACHE = 100


def _purge():
def _purge() -> None:
"""Clear the pattern cache"""
_cache.clear()

@@ -60,7 +60,7 @@ def fnmatchcase(name, pat):
return re_pat.match(name) is not None


def translate(pat):
def translate(pat) -> str:
"""Translate a shell PATTERN to a regular expression.
There is no way to quote meta-characters.
6 changes: 3 additions & 3 deletions docker/utils/ports.py
Original file line number Diff line number Diff line change
@@ -12,14 +12,14 @@
)


def add_port_mapping(port_bindings, internal_port, external):
def add_port_mapping(port_bindings, internal_port, external) -> None:
if internal_port in port_bindings:
port_bindings[internal_port].append(external)
else:
port_bindings[internal_port] = [external]


def add_port(port_bindings, internal_port_range, external_range):
def add_port(port_bindings, internal_port_range, external_range) -> None:
if external_range is None:
for internal_port in internal_port_range:
add_port_mapping(port_bindings, internal_port, None)
@@ -37,7 +37,7 @@ def build_port_bindings(ports):
return port_bindings


def _raise_invalid_port(port):
def _raise_invalid_port(port) -> None:
raise ValueError('Invalid port "%s", should be '
'[[remote_ip:]remote_port[-remote_port]:]'
'port[/protocol]' % port)
2 changes: 1 addition & 1 deletion docker/utils/proxy.py
Original file line number Diff line number Diff line change
@@ -68,7 +68,7 @@ def inject_proxy_environment(self, environment):
# variables defined in "environment" to take precedence.
return proxy_env + environment

def __str__(self):
def __str__(self) -> str:
return (
'ProxyConfig('
f'http={self.http}, https={self.https}, '
10 changes: 5 additions & 5 deletions docker/utils/utils.py
Original file line number Diff line number Diff line change
@@ -24,14 +24,14 @@
)


def create_ipam_pool(*args, **kwargs):
def create_ipam_pool(*args, **kwargs) -> None:
raise errors.DeprecatedMethod(
'utils.create_ipam_pool has been removed. Please use a '
'docker.types.IPAMPool object instead.'
)


def create_ipam_config(*args, **kwargs):
def create_ipam_config(*args, **kwargs) -> None:
raise errors.DeprecatedMethod(
'utils.create_ipam_config has been removed. Please use a '
'docker.types.IPAMConfig object instead.'
@@ -45,7 +45,7 @@ def decode_json_header(header):


@lru_cache(maxsize=None)
def compare_version(v1, v2):
def compare_version(v1, v2) -> int:
"""Compare docker versions
>>> v1 = '1.9'
@@ -77,7 +77,7 @@ def version_lt(v1, v2):
return compare_version(v1, v2) > 0


def version_gte(v1, v2):
def version_gte(v1, v2) -> bool:
return not version_lt(v1, v2)


@@ -509,7 +509,7 @@ def format_extra_hosts(extra_hosts, task=False):
]


def create_host_config(self, *args, **kwargs):
def create_host_config(self, *args, **kwargs) -> None:
raise errors.DeprecatedMethod(
'utils.create_host_config has been removed. Please use a '
'docker.types.HostConfig object instead.'