Run pyupgrade to clean up Python 2 syntaxes

Update all .py source files by
 $ pyupgrade --py3-only $(git ls-files | grep ".py$")
to modernize the code according to Python 3 syntaxes.

Also add the pyupgrade hook to pre-commit to avoid merging additional
Python 2 syntaxes.

Change-Id: Ieaccbf47ceccade0bd109f42769e42bca0edd0f4
This commit is contained in:
Takashi Kajinami
2025-01-13 13:50:02 +09:00
parent 1b45439f02
commit b3eb108ad3
6 changed files with 13 additions and 14 deletions

View File

@@ -28,3 +28,8 @@ repos:
hooks:
- id: bandit
args: ['-x', 'tests']
- repo: https://github.com/asottile/pyupgrade
rev: v3.18.0
hooks:
- id: pyupgrade
args: [--py3-only]

View File

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

View File

@@ -53,7 +53,7 @@ class MessageRouter():
try:
metric_definition = getattr(mod, metric.name)
except AttributeError as e:
LOG.error("Failed to load metrics %s: %s" % (metric.name, e))
LOG.error("Failed to load metrics {}: {}".format(metric.name, e))
return
# Get labels
@@ -64,7 +64,7 @@ class MessageRouter():
LOG.error("Failed to load labels func from metrics %s: %s" %
(metric.name, e))
return
LOG.debug("Get labels with %s: %s" % (metric.name, metric.labels))
LOG.debug("Get labels with {}: {}".format(metric.name, metric.labels))
# perform action
try:

View File

@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
@@ -28,10 +26,10 @@ import prometheus_client
class TestProcessMessage(base.BaseTestCase):
def setUp(self):
super(TestProcessMessage, self).setUp()
super().setUp()
def test_process_counter(self):
received_json = """{
received_json = b"""{
"module": "oslo_messaging",
"name": "rpc_server_invocation_start_total",
"action": {
@@ -48,7 +46,7 @@ class TestProcessMessage(base.BaseTestCase):
"method": "get",
"process": "done"
}
}""".encode()
}"""
with mock.patch.object(
prometheus_client.Counter, 'inc',
@@ -58,7 +56,7 @@ class TestProcessMessage(base.BaseTestCase):
mock_inc.assert_called_once_with()
def test_process_histogram(self):
received_json = """{
received_json = b"""{
"module": "oslo_messaging",
"name": "rpc_client_processing_seconds",
"action": {
@@ -77,7 +75,7 @@ class TestProcessMessage(base.BaseTestCase):
"fanout": "foo",
"timeout": 10
}
}""".encode()
}"""
with mock.patch.object(
prometheus_client.Histogram, 'observe',

View File

@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
@@ -25,7 +23,7 @@ from oslotest import base
class TestMetricValidation(base.BaseTestCase):
def setUp(self):
super(TestMetricValidation, self).setUp()
super().setUp()
def assertRaisesWithMessage(self, message, func, *args, **kwargs):
try:

View File

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at