diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 85377ed..2399c1d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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] diff --git a/doc/source/conf.py b/doc/source/conf.py index 828b915..06a7769 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright (C) 2020 Red Hat, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/oslo_limit/exception.py b/oslo_limit/exception.py index 3f1d0ec..0bd8486 100644 --- a/oslo_limit/exception.py +++ b/oslo_limit/exception.py @@ -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) diff --git a/oslo_limit/fixture.py b/oslo_limit/fixture.py index dfea2cb..38aad0c 100644 --- a/oslo_limit/fixture.py +++ b/oslo_limit/fixture.py @@ -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() diff --git a/oslo_limit/limit.py b/oslo_limit/limit.py index bd8b1e6..4f95a5d 100644 --- a/oslo_limit/limit.py +++ b/oslo_limit/limit.py @@ -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 @@ -55,7 +53,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. @@ -190,7 +188,7 @@ class Enforcer(object): resources_to_check) -class _FlatEnforcer(object): +class _FlatEnforcer: name = 'flat' @@ -221,7 +219,7 @@ class _FlatEnforcer(object): current_usage, deltas) -class _StrictTwoLevelEnforcer(object): +class _StrictTwoLevelEnforcer: name = 'strict-two-level' @@ -246,13 +244,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): diff --git a/oslo_limit/tests/test_fixture.py b/oslo_limit/tests/test_fixture.py index 61fde1b..95b5c1f 100644 --- a/oslo_limit/tests/test_fixture.py +++ b/oslo_limit/tests/test_fixture.py @@ -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( diff --git a/oslo_limit/tests/test_limit.py b/oslo_limit/tests/test_limit.py index 79e6e0a..0605727 100644 --- a/oslo_limit/tests/test_limit.py +++ b/oslo_limit/tests/test_limit.py @@ -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 @@ -42,7 +40,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( @@ -229,7 +227,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', @@ -322,7 +320,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', diff --git a/releasenotes/source/conf.py b/releasenotes/source/conf.py index 61d652b..b0dd26a 100644 --- a/releasenotes/source/conf.py +++ b/releasenotes/source/conf.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright (C) 2020 Red Hat, Inc. # # Licensed under the Apache License, Version 2.0 (the "License");