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:
parent
14ea68e4b8
commit
585d49fa30
@ -28,3 +28,8 @@ repos:
|
|||||||
hooks:
|
hooks:
|
||||||
- id: bandit
|
- id: bandit
|
||||||
args: ['-x', 'tests']
|
args: ['-x', 'tests']
|
||||||
|
- repo: https://github.com/asottile/pyupgrade
|
||||||
|
rev: v3.18.0
|
||||||
|
hooks:
|
||||||
|
- id: pyupgrade
|
||||||
|
args: [--py3-only]
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
# Copyright (C) 2020 Red Hat, Inc.
|
# Copyright (C) 2020 Red Hat, Inc.
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
# 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
|
# not use this file except in compliance with the License. You may obtain
|
||||||
# a copy of the License at
|
# a copy of the License at
|
||||||
@ -35,10 +33,10 @@ class ProjectOverLimit(Exception):
|
|||||||
msg = _("Project %(project_id)s is over a limit for "
|
msg = _("Project %(project_id)s is over a limit for "
|
||||||
"%(limits)s") % {'project_id': project_id,
|
"%(limits)s") % {'project_id': project_id,
|
||||||
'limits': over_limit_info_list}
|
'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):
|
def __init__(self, resource_name, limit, current_usage, delta):
|
||||||
self.resource_name = resource_name
|
self.resource_name = resource_name
|
||||||
self.limit = int(limit)
|
self.limit = int(limit)
|
||||||
@ -60,4 +58,4 @@ class SessionInitError(Exception):
|
|||||||
msg = _(
|
msg = _(
|
||||||
"Can't initialise OpenStackSDK session: %(reason)s."
|
"Can't initialise OpenStackSDK session: %(reason)s."
|
||||||
) % {'reason': reason}
|
) % {'reason': reason}
|
||||||
super(SessionInitError, self).__init__(msg)
|
super().__init__(msg)
|
||||||
|
@ -37,7 +37,7 @@ class LimitFixture(fixtures.Fixture):
|
|||||||
self.projlimits = projlimits
|
self.projlimits = projlimits
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(LimitFixture, self).setUp()
|
super().setUp()
|
||||||
|
|
||||||
# We mock our own cached connection to Keystone
|
# We mock our own cached connection to Keystone
|
||||||
self.mock_conn = mock.MagicMock()
|
self.mock_conn = mock.MagicMock()
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
# 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
|
# not use this file except in compliance with the License. You may obtain
|
||||||
# a copy of the License at
|
# a copy of the License at
|
||||||
@ -54,7 +52,7 @@ def _get_keystone_connection():
|
|||||||
return _SDK_CONNECTION
|
return _SDK_CONNECTION
|
||||||
|
|
||||||
|
|
||||||
class Enforcer(object):
|
class Enforcer:
|
||||||
|
|
||||||
def __init__(self, usage_callback, cache=True):
|
def __init__(self, usage_callback, cache=True):
|
||||||
"""An object for checking usage against resource limits and requests.
|
"""An object for checking usage against resource limits and requests.
|
||||||
@ -189,7 +187,7 @@ class Enforcer(object):
|
|||||||
resources_to_check)
|
resources_to_check)
|
||||||
|
|
||||||
|
|
||||||
class _FlatEnforcer(object):
|
class _FlatEnforcer:
|
||||||
|
|
||||||
name = 'flat'
|
name = 'flat'
|
||||||
|
|
||||||
@ -220,7 +218,7 @@ class _FlatEnforcer(object):
|
|||||||
current_usage, deltas)
|
current_usage, deltas)
|
||||||
|
|
||||||
|
|
||||||
class _StrictTwoLevelEnforcer(object):
|
class _StrictTwoLevelEnforcer:
|
||||||
|
|
||||||
name = 'strict-two-level'
|
name = 'strict-two-level'
|
||||||
|
|
||||||
@ -245,13 +243,13 @@ _MODELS = [_FlatEnforcer, _StrictTwoLevelEnforcer]
|
|||||||
|
|
||||||
class _LimitNotFound(Exception):
|
class _LimitNotFound(Exception):
|
||||||
def __init__(self, resource):
|
def __init__(self, resource):
|
||||||
msg = "Can't find the limit for resource %(resource)s" % {
|
msg = "Can't find the limit for resource {resource}".format(
|
||||||
'resource': resource}
|
resource=resource)
|
||||||
self.resource = resource
|
self.resource = resource
|
||||||
super(_LimitNotFound, self).__init__(msg)
|
super().__init__(msg)
|
||||||
|
|
||||||
|
|
||||||
class _EnforcerUtils(object):
|
class _EnforcerUtils:
|
||||||
"""Logic common used by multiple enforcers"""
|
"""Logic common used by multiple enforcers"""
|
||||||
|
|
||||||
def __init__(self, cache=True):
|
def __init__(self, cache=True):
|
||||||
|
@ -26,7 +26,7 @@ CONF = cfg.CONF
|
|||||||
|
|
||||||
class TestFixture(base.BaseTestCase):
|
class TestFixture(base.BaseTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestFixture, self).setUp()
|
super().setUp()
|
||||||
|
|
||||||
self.config_fixture = self.useFixture(config_fixture.Config(CONF))
|
self.config_fixture = self.useFixture(config_fixture.Config(CONF))
|
||||||
self.config_fixture.config(
|
self.config_fixture.config(
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
# 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
|
# not use this file except in compliance with the License. You may obtain
|
||||||
# a copy of the License at
|
# a copy of the License at
|
||||||
@ -39,7 +37,7 @@ CONF = cfg.CONF
|
|||||||
class TestEnforcer(base.BaseTestCase):
|
class TestEnforcer(base.BaseTestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestEnforcer, self).setUp()
|
super().setUp()
|
||||||
self.deltas = dict()
|
self.deltas = dict()
|
||||||
self.config_fixture = self.useFixture(config_fixture.Config(CONF))
|
self.config_fixture = self.useFixture(config_fixture.Config(CONF))
|
||||||
self.config_fixture.config(
|
self.config_fixture.config(
|
||||||
@ -226,7 +224,7 @@ class TestEnforcer(base.BaseTestCase):
|
|||||||
|
|
||||||
class TestFlatEnforcer(base.BaseTestCase):
|
class TestFlatEnforcer(base.BaseTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestFlatEnforcer, self).setUp()
|
super().setUp()
|
||||||
self.config_fixture = self.useFixture(config_fixture.Config(CONF))
|
self.config_fixture = self.useFixture(config_fixture.Config(CONF))
|
||||||
self.config_fixture.config(
|
self.config_fixture.config(
|
||||||
group='oslo_limit',
|
group='oslo_limit',
|
||||||
@ -319,7 +317,7 @@ class TestFlatEnforcer(base.BaseTestCase):
|
|||||||
|
|
||||||
class TestEnforcerUtils(base.BaseTestCase):
|
class TestEnforcerUtils(base.BaseTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestEnforcerUtils, self).setUp()
|
super().setUp()
|
||||||
self.config_fixture = self.useFixture(config_fixture.Config(CONF))
|
self.config_fixture = self.useFixture(config_fixture.Config(CONF))
|
||||||
self.config_fixture.config(
|
self.config_fixture.config(
|
||||||
group='oslo_limit',
|
group='oslo_limit',
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
# Copyright (C) 2020 Red Hat, Inc.
|
# Copyright (C) 2020 Red Hat, Inc.
|
||||||
#
|
#
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
Loading…
Reference in New Issue
Block a user