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: I1f005fa2c925612ebfd97d0ca9c2727a4d162523
This commit is contained in:
Takashi Kajinami 2024-10-19 23:15:13 +09:00
parent 14ea68e4b8
commit 585d49fa30
8 changed files with 20 additions and 23 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 -*-
# Copyright (C) 2020 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");

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
@ -35,10 +33,10 @@ class ProjectOverLimit(Exception):
msg = _("Project %(project_id)s is over a limit for "
"%(limits)s") % {'project_id': project_id,
'limits': over_limit_info_list}
super(ProjectOverLimit, self).__init__(msg)
super().__init__(msg)
class OverLimitInfo(object):
class OverLimitInfo:
def __init__(self, resource_name, limit, current_usage, delta):
self.resource_name = resource_name
self.limit = int(limit)
@ -60,4 +58,4 @@ class SessionInitError(Exception):
msg = _(
"Can't initialise OpenStackSDK session: %(reason)s."
) % {'reason': reason}
super(SessionInitError, self).__init__(msg)
super().__init__(msg)

View File

@ -37,7 +37,7 @@ class LimitFixture(fixtures.Fixture):
self.projlimits = projlimits
def setUp(self):
super(LimitFixture, self).setUp()
super().setUp()
# We mock our own cached connection to Keystone
self.mock_conn = mock.MagicMock()

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
@ -54,7 +52,7 @@ def _get_keystone_connection():
return _SDK_CONNECTION
class Enforcer(object):
class Enforcer:
def __init__(self, usage_callback, cache=True):
"""An object for checking usage against resource limits and requests.
@ -189,7 +187,7 @@ class Enforcer(object):
resources_to_check)
class _FlatEnforcer(object):
class _FlatEnforcer:
name = 'flat'
@ -220,7 +218,7 @@ class _FlatEnforcer(object):
current_usage, deltas)
class _StrictTwoLevelEnforcer(object):
class _StrictTwoLevelEnforcer:
name = 'strict-two-level'
@ -245,13 +243,13 @@ _MODELS = [_FlatEnforcer, _StrictTwoLevelEnforcer]
class _LimitNotFound(Exception):
def __init__(self, resource):
msg = "Can't find the limit for resource %(resource)s" % {
'resource': resource}
msg = "Can't find the limit for resource {resource}".format(
resource=resource)
self.resource = resource
super(_LimitNotFound, self).__init__(msg)
super().__init__(msg)
class _EnforcerUtils(object):
class _EnforcerUtils:
"""Logic common used by multiple enforcers"""
def __init__(self, cache=True):

View File

@ -26,7 +26,7 @@ CONF = cfg.CONF
class TestFixture(base.BaseTestCase):
def setUp(self):
super(TestFixture, self).setUp()
super().setUp()
self.config_fixture = self.useFixture(config_fixture.Config(CONF))
self.config_fixture.config(

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
@ -39,7 +37,7 @@ CONF = cfg.CONF
class TestEnforcer(base.BaseTestCase):
def setUp(self):
super(TestEnforcer, self).setUp()
super().setUp()
self.deltas = dict()
self.config_fixture = self.useFixture(config_fixture.Config(CONF))
self.config_fixture.config(
@ -226,7 +224,7 @@ class TestEnforcer(base.BaseTestCase):
class TestFlatEnforcer(base.BaseTestCase):
def setUp(self):
super(TestFlatEnforcer, self).setUp()
super().setUp()
self.config_fixture = self.useFixture(config_fixture.Config(CONF))
self.config_fixture.config(
group='oslo_limit',
@ -319,7 +317,7 @@ class TestFlatEnforcer(base.BaseTestCase):
class TestEnforcerUtils(base.BaseTestCase):
def setUp(self):
super(TestEnforcerUtils, self).setUp()
super().setUp()
self.config_fixture = self.useFixture(config_fixture.Config(CONF))
self.config_fixture.config(
group='oslo_limit',

View File

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2020 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");