From 725867fd36e7a9ee52e2f5f2d4624777331d1959 Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Sun, 5 Oct 2025 19:27:39 +0900 Subject: [PATCH] Bump pyupgrade target to 3.10+ ... according to the versions currently supported. Change-Id: I93f0eed8b29cbb7779899ba9895e4f4233a884fa Signed-off-by: Takashi Kajinami --- .pre-commit-config.yaml | 2 +- doc/source/ext/gen_ref.py | 2 +- heatclient/common/base.py | 14 +++++++------- heatclient/common/deployment_utils.py | 4 ++-- heatclient/common/event_utils.py | 2 +- heatclient/common/format_utils.py | 4 ++-- heatclient/common/http.py | 4 ++-- heatclient/common/resource_formatter.py | 2 +- heatclient/shell.py | 2 +- heatclient/tests/unit/test_shell.py | 18 +++++++++--------- heatclient/tests/unit/test_stacks.py | 2 +- heatclient/tests/unit/test_template_utils.py | 2 +- heatclient/v1/stacks.py | 2 +- 13 files changed, 30 insertions(+), 30 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1e3520e7..b7c45c83 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -27,4 +27,4 @@ repos: rev: v3.20.0 hooks: - id: pyupgrade - args: [--py3-only] + args: [--py310-plus] diff --git a/doc/source/ext/gen_ref.py b/doc/source/ext/gen_ref.py index 3886aba0..88bfc856 100644 --- a/doc/source/ext/gen_ref.py +++ b/doc/source/ext/gen_ref.py @@ -24,7 +24,7 @@ def gen_ref(ver, title, names): refdir = os.path.join(BASE_DIR, "ref") pkg = "heatclient" if ver: - pkg = "{}.{}".format(pkg, ver) + pkg = f"{pkg}.{ver}" refdir = os.path.join(refdir, ver) if not os.path.exists(refdir): os.makedirs(refdir) diff --git a/heatclient/common/base.py b/heatclient/common/base.py index 2ec763e5..b19c8052 100644 --- a/heatclient/common/base.py +++ b/heatclient/common/base.py @@ -282,7 +282,7 @@ class CrudManager(BaseManager): url = '/'.join([url, self.collection_key]) # do we have a specific entity? - entity_id = kwargs.get('{}_id'.format(self.key)) + entity_id = kwargs.get(f'{self.key}_id') if entity_id is not None: url = '/'.join([url, entity_id]) @@ -322,7 +322,7 @@ class CrudManager(BaseManager): :param base_url: if provided, the generated URL will be appended to it """ kwargs = self._filter_kwargs(kwargs) - query = '?{}'.format(parse.urlencode(kwargs)) if kwargs else '' + query = f'?{parse.urlencode(kwargs)}' if kwargs else '' return self._list( '{base_url}{query}'.format( @@ -343,7 +343,7 @@ class CrudManager(BaseManager): def update(self, **kwargs): kwargs = self._filter_kwargs(kwargs) params = kwargs.copy() - params.pop('{}_id'.format(self.key)) + params.pop(f'{self.key}_id') return self._patch( self.build_url(**kwargs), @@ -362,7 +362,7 @@ class CrudManager(BaseManager): :param base_url: if provided, the generated URL will be appended to it """ kwargs = self._filter_kwargs(kwargs) - query = '?{}'.format(parse.urlencode(kwargs)) if kwargs else '' + query = f'?{parse.urlencode(kwargs)}' if kwargs else '' rl = self._list( '{base_url}{query}'.format( @@ -409,7 +409,7 @@ class Extension(HookableMixin): pass def __repr__(self): - return "".format(self.name) + return f"" class Resource: @@ -436,9 +436,9 @@ class Resource: reprkeys = sorted(k for k in self.__dict__ if k[0] != '_' and k != 'manager') - info = ", ".join("{}={}".format(k, getattr(self, k)) for k in reprkeys) + info = ", ".join(f"{k}={getattr(self, k)}" for k in reprkeys) class_name = reflection.get_class_name(self, fully_qualified=False) - return "<{} {}>".format(class_name, info) + return f"<{class_name} {info}>" @property def human_id(self): diff --git a/heatclient/common/deployment_utils.py b/heatclient/common/deployment_utils.py index 05e813d9..8546c5a5 100644 --- a/heatclient/common/deployment_utils.py +++ b/heatclient/common/deployment_utils.py @@ -105,12 +105,12 @@ def create_temp_url(swift_client, name, timeout, container=None): key = swift_client.head_account()[key_header] project_path = swift_client.url.split('/')[-1] - path = '/v1/{}/{}/{}'.format(project_path, container, object_name) + path = f'/v1/{project_path}/{container}/{object_name}' timeout_secs = timeout * 60 tempurl = swiftclient_utils.generate_temp_url(path, timeout_secs, key, 'PUT') sw_url = urlparse.urlparse(swift_client.url) - put_url = '{}://{}{}'.format(sw_url.scheme, sw_url.netloc, tempurl) + put_url = f'{sw_url.scheme}://{sw_url.netloc}{tempurl}' swift_client.put_object(container, object_name, '') return put_url diff --git a/heatclient/common/event_utils.py b/heatclient/common/event_utils.py index 24b636d6..ca213257 100644 --- a/heatclient/common/event_utils.py +++ b/heatclient/common/event_utils.py @@ -261,4 +261,4 @@ def wait_for_events(ws, stack_name, out=None): if stack_status in ('COMPLETE', 'FAILED'): msg = msg_template % dict( name=stack_name, status=event.resource_status) - return '{}_{}'.format(event.resource_action, stack_status), msg + return f'{event.resource_action}_{stack_status}', msg diff --git a/heatclient/common/format_utils.py b/heatclient/common/format_utils.py index db43a98f..4151c80e 100644 --- a/heatclient/common/format_utils.py +++ b/heatclient/common/format_utils.py @@ -90,6 +90,6 @@ def print_software_deployment_output(data, name, out=sys.stdout, long=False): truncate=not long, truncate_prefix='...', truncate_postfix='(truncated, view all with --long)') - out.write(' {}: |\n{}\n'.format(name, output)) + out.write(f' {name}: |\n{output}\n') else: - out.write(' {}: {}\n'.format(name, data.get(name))) + out.write(f' {name}: {data.get(name)}\n') diff --git a/heatclient/common/http.py b/heatclient/common/http.py index af3d7d9e..8d7a548a 100644 --- a/heatclient/common/http.py +++ b/heatclient/common/http.py @@ -146,7 +146,7 @@ class HTTPClient: def log_http_response(resp): status = (resp.raw.version / 10.0, resp.status_code, resp.reason) dump = ['\nHTTP/%.1f %s %s' % status] - dump.extend(['{}: {}'.format(k, v) for k, v in resp.headers.items()]) + dump.extend([f'{k}: {v}' for k, v in resp.headers.items()]) dump.append('') if resp.content: content = resp.content @@ -216,7 +216,7 @@ class HTTPClient: message = (_("Error finding address for %(url)s: %(e)s") % {'url': self.endpoint_url + url, 'e': e}) raise exc.InvalidEndpoint(message=message) - except (OSError, socket.timeout) as e: + except (OSError, TimeoutError) as e: endpoint = self.endpoint message = (_("Error communicating with %(endpoint)s %(e)s") % {'endpoint': endpoint, 'e': e}) diff --git a/heatclient/common/resource_formatter.py b/heatclient/common/resource_formatter.py index 0e49a548..3cfb63f1 100644 --- a/heatclient/common/resource_formatter.py +++ b/heatclient/common/resource_formatter.py @@ -34,7 +34,7 @@ class ResourceDotInfo: if not prefix: prefix = 'r' hash_object = hashlib.sha256(url.encode('utf-8')) - return '{}_{}'.format(prefix, hash_object.hexdigest()[:20]) + return f'{prefix}_{hash_object.hexdigest()[:20]}' class ResourceDotFormatter(base.ListFormatter): diff --git a/heatclient/shell.py b/heatclient/shell.py index a0fb194b..9a4cc385 100644 --- a/heatclient/shell.py +++ b/heatclient/shell.py @@ -592,7 +592,7 @@ class HeatShell: class HelpFormatter(argparse.HelpFormatter): def start_section(self, heading): # Title-case the headings - heading = '{}{}'.format(heading[0].upper(), heading[1:]) + heading = f'{heading[0].upper()}{heading[1:]}' super().start_section(heading) diff --git a/heatclient/tests/unit/test_shell.py b/heatclient/tests/unit/test_shell.py index d6a378a9..867a70ba 100644 --- a/heatclient/tests/unit/test_shell.py +++ b/heatclient/tests/unit/test_shell.py @@ -192,7 +192,7 @@ class TestCase(testtools.TestCase): "logical_resource_id": "myDeployment", "physical_resource_id": "bce15ec4-8919-4a02-8a90-680960fb3731", "resource_name": rn, - "resource_status": "{}_{}".format(action, final_state), + "resource_status": f"{action}_{final_state}", "resource_status_reason": "state changed"}]} if resource_name is None: @@ -227,7 +227,7 @@ class TestCase(testtools.TestCase): "logical_resource_id": "aResource", "physical_resource_id": 'foo3', "resource_name": stack_name, - "resource_status": "{}_{}".format(action, final_state), + "resource_status": f"{action}_{final_state}", "resource_status_reason": "state changed"}) return resp_dict @@ -320,7 +320,7 @@ class ShellParamValidationTest(TestCase): if self.with_tmpl: template_file = os.path.join(TEST_VAR_DIR, 'minimal.template') - cmd = '{} --template-file={} '.format(self.command, template_file) + cmd = f'{self.command} --template-file={template_file} ' self.shell_error(cmd, self.err, exception=exc.CommandError) @@ -2731,7 +2731,7 @@ class ShellTestEventsNested(ShellBase): stack_id = 'teststack/1' error = self.assertRaises( exc.CommandError, self.shell, - 'event-list {} --nested-depth Z'.format(stack_id)) + f'event-list {stack_id} --nested-depth Z') self.assertIn('--nested-depth invalid value Z', str(error)) def test_shell_nested_depth_zero(self): @@ -2955,7 +2955,7 @@ class ShellTestHookFunctions(ShellBase): resp_dict = {"stack": { "id": stack_id.split("/")[1], "stack_name": stack_id.split("/")[0], - "stack_status": '{}_{}'.format(action, status), + "stack_status": f'{action}_{status}', "creation_time": "2014-01-06T16:14:00Z", }} self.mock_request_get('/stacks/teststack/1', resp_dict) @@ -3113,7 +3113,7 @@ class ShellTestResources(ShellBase): stack_id = 'teststack/1' self.mock_request_get('/stacks/%s/resources' % stack_id, resp_dict) - resource_list_text = self.shell('resource-list {}'.format(stack_id)) + resource_list_text = self.shell(f'resource-list {stack_id}') required = [ 'physical_resource_id', @@ -3147,7 +3147,7 @@ class ShellTestResources(ShellBase): stack_id = 'teststack/1' self.mock_request_get('/stacks/%s/resources' % stack_id, resp_dict) - resource_list_text = self.shell('resource-list {}'.format(stack_id)) + resource_list_text = self.shell(f'resource-list {stack_id}') self.assertEqual('''\ +---------------+----------------------+---------------+-----------------+\ @@ -3177,7 +3177,7 @@ class ShellTestResources(ShellBase): self.mock_request_get('/stacks/{}/resources?{}'.format( stack_id, query_args), resp_dict) - shell_cmd = 'resource-list {} {}'.format(stack_id, cmd_args) + shell_cmd = f'resource-list {stack_id} {cmd_args}' resource_list_text = self.shell(shell_cmd) @@ -3297,7 +3297,7 @@ class ShellTestResources(ShellBase): ) text = self.shell( - 'resource-signal {} {}'.format(stack_id, resource_name)) + f'resource-signal {stack_id} {resource_name}') self.assertEqual("", text) def test_resource_signal_no_json(self): diff --git a/heatclient/tests/unit/test_stacks.py b/heatclient/tests/unit/test_stacks.py index 02627cfd..2ba5ab28 100644 --- a/heatclient/tests/unit/test_stacks.py +++ b/heatclient/tests/unit/test_stacks.py @@ -54,7 +54,7 @@ class StackStatusActionTest(testtools.TestCase): ]) def test_status_action(self): - stack_status = '{}_{}'.format(self.action, self.status) + stack_status = f'{self.action}_{self.status}' stack = mock_stack(None, 'stack_1', 'abcd1234') stack.stack_status = stack_status self.assertEqual(self.action, stack.action) diff --git a/heatclient/tests/unit/test_template_utils.py b/heatclient/tests/unit/test_template_utils.py index 4bdde49d..ee81d1d6 100644 --- a/heatclient/tests/unit/test_template_utils.py +++ b/heatclient/tests/unit/test_template_utils.py @@ -716,7 +716,7 @@ class TestGetTemplateContents(testtools.TestCase): def check_non_utf8_content(self, filename, content): base_url = 'file:///tmp' - url = '{}/{}'.format(base_url, filename) + url = f'{base_url}/{filename}' template = {'resources': {'one_init': {'type': 'OS::Heat::CloudConfig', diff --git a/heatclient/v1/stacks.py b/heatclient/v1/stacks.py index 329b81f2..f784d0b3 100644 --- a/heatclient/v1/stacks.py +++ b/heatclient/v1/stacks.py @@ -91,7 +91,7 @@ class Stack(base.Resource): @property def identifier(self): - return '{}/{}'.format(self.stack_name, self.id) + return f'{self.stack_name}/{self.id}' class StackChildManager(base.BaseManager):