Skip to content

Commit

Permalink
trivial: Prepare for pyupgrade pre-commit hook
Browse files Browse the repository at this point in the history
This change is entirely automated save for the update of some mocks from
'io.open' to '__builtins__.open').

We are keeping this change separate from addition of the actual hook so
that we can ignore the commit later.

Change-Id: I0a9d8736632084473b57b57b693322447d7be519
Signed-off-by: Stephen Finucane <[email protected]>
  • Loading branch information
stephenfin committed Apr 23, 2024
1 parent 3de6969 commit c5b772d
Show file tree
Hide file tree
Showing 274 changed files with 1,291 additions and 1,325 deletions.
1 change: 0 additions & 1 deletion doc/source/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# OpenStack Command Line Client documentation build configuration file, created
# by sphinx-quickstart on Wed May 16 12:05:58 2012.
Expand Down
2 changes: 1 addition & 1 deletion doc/source/contributor/command-errors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ raised that includes the name of the file that was attempted to be opened.
public_key = parsed_args.public_key
if public_key:
try:
with io.open(
with open(
os.path.expanduser(parsed_args.public_key),
"rb"
) as p:
Expand Down
8 changes: 4 additions & 4 deletions openstackclient/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from openstackclient.i18n import _


class KeystoneSession(object):
class KeystoneSession:
"""Wrapper for the Keystone Session
Restore some requests.session.Session compatibility;
Expand All @@ -40,7 +40,7 @@ def __init__(self, session=None, endpoint=None, **kwargs):
requests on this API.
"""

super(KeystoneSession, self).__init__()
super().__init__()

# a requests.Session-style interface
self.session = session
Expand Down Expand Up @@ -95,7 +95,7 @@ def __init__(
requests on this API.
"""

super(BaseAPI, self).__init__(session=session, endpoint=endpoint)
super().__init__(session=session, endpoint=endpoint)

self.service_type = service_type

Expand Down Expand Up @@ -303,7 +303,7 @@ def find(
"""

try:
ret = self._request('GET', "/%s/%s" % (path, value)).json()
ret = self._request('GET', f"/{path}/{value}").json()
except ks_exceptions.NotFound:
kwargs = {attr: value}
try:
Expand Down
24 changes: 12 additions & 12 deletions openstackclient/api/compute_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class APIv2(api.BaseAPI):
"""Compute v2 API"""

def __init__(self, **kwargs):
super(APIv2, self).__init__(**kwargs)
super().__init__(**kwargs)

# Overrides

Expand Down Expand Up @@ -76,7 +76,7 @@ def find(
"""

try:
ret = self._request('GET', "/%s/%s" % (path, value)).json()
ret = self._request('GET', f"/{path}/{value}").json()
if isinstance(ret, dict):
# strip off the enclosing dict
key = list(ret.keys())[0]
Expand Down Expand Up @@ -136,7 +136,7 @@ def floating_ip_add(

return self._request(
"POST",
"/%s/%s/action" % (url, server['id']),
"/{}/{}/action".format(url, server['id']),
json={'addFloatingIp': body},
)

Expand Down Expand Up @@ -180,7 +180,7 @@ def floating_ip_delete(
url = "/os-floating-ips"

if floating_ip_id is not None:
return self.delete('/%s/%s' % (url, floating_ip_id))
return self.delete(f'/{url}/{floating_ip_id}')

return None

Expand Down Expand Up @@ -248,7 +248,7 @@ def floating_ip_remove(

return self._request(
"POST",
"/%s/%s/action" % (url, server['id']),
"/{}/{}/action".format(url, server['id']),
json={'removeFloatingIp': body},
)

Expand Down Expand Up @@ -316,7 +316,7 @@ def host_set(
else:
return self._request(
"PUT",
"/%s/%s" % (url, host),
f"/{url}/{host}",
json=params,
).json()

Expand Down Expand Up @@ -398,7 +398,7 @@ def network_delete(
value=network,
)['id']
if network is not None:
return self.delete('/%s/%s' % (url, network))
return self.delete(f'/{url}/{network}')

return None

Expand Down Expand Up @@ -487,7 +487,7 @@ def security_group_delete(
value=security_group,
)['id']
if security_group is not None:
return self.delete('/%s/%s' % (url, security_group))
return self.delete(f'/{url}/{security_group}')

return None

Expand Down Expand Up @@ -535,7 +535,7 @@ def security_group_list(

params = {}
if search_opts is not None:
params = dict((k, v) for (k, v) in search_opts.items() if v)
params = {k: v for (k, v) in search_opts.items() if v}
if limit:
params['limit'] = limit
if marker:
Expand All @@ -549,7 +549,7 @@ def security_group_set(
security_group=None,
# name=None,
# description=None,
**params
**params,
):
"""Update a security group
Expand Down Expand Up @@ -579,7 +579,7 @@ def security_group_set(
security_group[k] = v
return self._request(
"PUT",
"/%s/%s" % (url, security_group['id']),
"/{}/{}".format(url, security_group['id']),
json={'security_group': security_group},
).json()['security_group']
return None
Expand Down Expand Up @@ -648,6 +648,6 @@ def security_group_rule_delete(

url = "/os-security-group-rules"
if security_group_rule_id is not None:
return self.delete('/%s/%s' % (url, security_group_rule_id))
return self.delete(f'/{url}/{security_group_rule_id}')

return None
2 changes: 1 addition & 1 deletion openstackclient/api/image_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class APIv1(api.BaseAPI):
_endpoint_suffix = '/v1'

def __init__(self, endpoint=None, **kwargs):
super(APIv1, self).__init__(endpoint=endpoint, **kwargs)
super().__init__(endpoint=endpoint, **kwargs)

self.endpoint = self.endpoint.rstrip('/')
self._munge_url()
Expand Down
7 changes: 3 additions & 4 deletions openstackclient/api/object_store_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

"""Object Store v1 API Library"""

import io
import logging
import os
import sys
Expand All @@ -33,7 +32,7 @@ class APIv1(api.BaseAPI):
"""Object Store v1 API"""

def __init__(self, **kwargs):
super(APIv1, self).__init__(**kwargs)
super().__init__(**kwargs)

def container_create(
self, container=None, public=False, storage_policy=None
Expand Down Expand Up @@ -257,11 +256,11 @@ def object_create(
# object's name in the container.
object_name_str = name if name else object

full_url = "%s/%s" % (
full_url = "{}/{}".format(
urllib.parse.quote(container),
urllib.parse.quote(object_name_str),
)
with io.open(object, 'rb') as f:
with open(object, 'rb') as f:
response = self.create(
full_url,
method='PUT',
Expand Down
2 changes: 1 addition & 1 deletion openstackclient/common/availability_zone.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def _xform_compute_availability_zone(az, include_extra):
for svc, state in services.items():
info = copy.deepcopy(host_info)
info['service_name'] = svc
info['service_status'] = '%s %s %s' % (
info['service_status'] = '{} {} {}'.format(
'enabled' if state['active'] else 'disabled',
':-)' if state['available'] else 'XXX',
state['updated_at'],
Expand Down
8 changes: 5 additions & 3 deletions openstackclient/common/clientmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def __init__(
api_version=None,
pw_func=None,
):
super(ClientManager, self).__init__(
super().__init__(
cli_options=cli_options,
api_version=api_version,
pw_func=pw_func,
Expand Down Expand Up @@ -94,7 +94,7 @@ def setup_auth(self):
except TypeError as e:
self._fallback_load_auth_plugin(e)

return super(ClientManager, self).setup_auth()
return super().setup_auth()

def _fallback_load_auth_plugin(self, e):
# NOTES(RuiChen): Hack to avoid auth plugins choking on data they don't
Expand Down Expand Up @@ -170,7 +170,9 @@ def get_plugin_modules(group):
module = importlib.import_module(module_name)
except Exception as err:
sys.stderr.write(
"WARNING: Failed to import plugin %s: %s.\n" % (ep.name, err)
"WARNING: Failed to import plugin {}: {}.\n".format(
ep.name, err
)
)
continue

Expand Down
2 changes: 1 addition & 1 deletion openstackclient/common/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ShowConfiguration(command.ShowOne):
auth_required = False

def get_parser(self, prog_name):
parser = super(ShowConfiguration, self).get_parser(prog_name)
parser = super().get_parser(prog_name)
mask_group = parser.add_mutually_exclusive_group()
mask_group.add_argument(
"--mask",
Expand Down
2 changes: 1 addition & 1 deletion openstackclient/common/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class ShowExtension(command.ShowOne):
_description = _("Show API extension")

def get_parser(self, prog_name):
parser = super(ShowExtension, self).get_parser(prog_name)
parser = super().get_parser(prog_name)
parser.add_argument(
'extension',
metavar='<extension>',
Expand Down
2 changes: 1 addition & 1 deletion openstackclient/common/limits.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ShowLimits(command.Lister):
_description = _("Show compute and block storage limits")

def get_parser(self, prog_name):
parser = super(ShowLimits, self).get_parser(prog_name)
parser = super().get_parser(prog_name)
type_group = parser.add_mutually_exclusive_group(required=True)
type_group.add_argument(
"--absolute",
Expand Down
4 changes: 2 additions & 2 deletions openstackclient/common/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ListCommand(command.Lister):
auth_required = False

def get_parser(self, prog_name):
parser = super(ListCommand, self).get_parser(prog_name)
parser = super().get_parser(prog_name)
parser.add_argument(
'--group',
metavar='<group-keyword>',
Expand Down Expand Up @@ -72,7 +72,7 @@ class ListModule(command.ShowOne):
auth_required = False

def get_parser(self, prog_name):
parser = super(ListModule, self).get_parser(prog_name)
parser = super().get_parser(prog_name)
parser.add_argument(
'--all',
action='store_true',
Expand Down
4 changes: 2 additions & 2 deletions openstackclient/common/progressbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import sys


class _ProgressBarBase(object):
class _ProgressBarBase:
"""A progress bar provider for a wrapped object.
Base abstract class used by specific class wrapper to show
Expand All @@ -39,7 +39,7 @@ def _display_progress_bar(self, size_read):
self._percent += size_read / self._totalsize
# Output something like this: [==========> ] 49%
sys.stdout.write(
'\r[{0:<30}] {1:.0%}'.format(
'\r[{:<30}] {:.0%}'.format(
'=' * int(round(self._percent * 29)) + '>', self._percent
)
)
Expand Down
2 changes: 1 addition & 1 deletion openstackclient/common/project_cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class ProjectCleanup(command.Command):
_description = _("Clean resources associated with a project")

def get_parser(self, prog_name):
parser = super(ProjectCleanup, self).get_parser(prog_name)
parser = super().get_parser(prog_name)
action_group = parser.add_mutually_exclusive_group()
action_group.add_argument(
'--dry-run',
Expand Down
8 changes: 4 additions & 4 deletions openstackclient/common/quota.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ def take_action(self, parsed_args):
and ex.http_status <= 499
):
# Project not found, move on to next one
LOG.warning("Project %s not found: %s" % (p, ex))
LOG.warning(f"Project {p} not found: {ex}")
continue
else:
raise
Expand Down Expand Up @@ -446,7 +446,7 @@ def take_action(self, parsed_args):
except Exception as ex:
if type(ex).__name__ == 'NotFound':
# Project not found, move on to next one
LOG.warning("Project %s not found: %s" % (p, ex))
LOG.warning(f"Project {p} not found: {ex}")
continue
else:
raise
Expand Down Expand Up @@ -500,7 +500,7 @@ def take_action(self, parsed_args):
except Exception as ex:
if type(ex).__name__ == 'NotFound':
# Project not found, move on to next one
LOG.warning("Project %s not found: %s" % (p, ex))
LOG.warning(f"Project {p} not found: {ex}")
continue
else:
raise
Expand Down Expand Up @@ -590,7 +590,7 @@ def _build_options_list(self):
return rets

def get_parser(self, prog_name):
parser = super(SetQuota, self).get_parser(prog_name)
parser = super().get_parser(prog_name)
parser.add_argument(
'project',
metavar='<project/class>',
Expand Down
2 changes: 1 addition & 1 deletion openstackclient/common/versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ShowVersions(command.Lister):
_description = _("Show available versions of services")

def get_parser(self, prog_name):
parser = super(ShowVersions, self).get_parser(prog_name)
parser = super().get_parser(prog_name)
interface_group = parser.add_mutually_exclusive_group()
interface_group.add_argument(
"--all-interfaces",
Expand Down
8 changes: 4 additions & 4 deletions openstackclient/compute/v2/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class CreateAgent(command.ShowOne):
"""

def get_parser(self, prog_name):
parser = super(CreateAgent, self).get_parser(prog_name)
parser = super().get_parser(prog_name)
parser.add_argument("os", metavar="<os>", help=_("Type of OS"))
parser.add_argument(
"architecture",
Expand Down Expand Up @@ -77,7 +77,7 @@ class DeleteAgent(command.Command):
"""

def get_parser(self, prog_name):
parser = super(DeleteAgent, self).get_parser(prog_name)
parser = super().get_parser(prog_name)
parser.add_argument(
"id", metavar="<id>", nargs='+', help=_("ID of agent(s) to delete")
)
Expand Down Expand Up @@ -114,7 +114,7 @@ class ListAgent(command.Lister):
"""

def get_parser(self, prog_name):
parser = super(ListAgent, self).get_parser(prog_name)
parser = super().get_parser(prog_name)
parser.add_argument(
"--hypervisor",
metavar="<hypervisor>",
Expand Down Expand Up @@ -155,7 +155,7 @@ class SetAgent(command.Command):
"""

def get_parser(self, prog_name):
parser = super(SetAgent, self).get_parser(prog_name)
parser = super().get_parser(prog_name)
parser.add_argument("id", metavar="<id>", help=_("ID of the agent"))
parser.add_argument(
"--agent-version",
Expand Down
Loading

0 comments on commit c5b772d

Please sign in to comment.