diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 10f19c51..2399c1d4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.5.0 + rev: v5.0.0 hooks: - id: trailing-whitespace # Replaces or checks mixed line ending @@ -19,12 +19,17 @@ repos: - id: check-yaml files: .*\.(yaml|yml)$ - repo: https://opendev.org/openstack/hacking - rev: 6.1.0 + rev: 7.0.0 hooks: - id: hacking additional_dependencies: [] - repo: https://github.com/PyCQA/bandit - rev: 1.7.6 + rev: 1.7.10 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 d347857a..3a763080 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -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 diff --git a/oslo_cache/backends/memcache_pool.py b/oslo_cache/backends/memcache_pool.py index 0ad36cb5..ae55d64d 100644 --- a/oslo_cache/backends/memcache_pool.py +++ b/oslo_cache/backends/memcache_pool.py @@ -31,7 +31,7 @@ from oslo_cache import exception # Helper to ease backend refactoring -class ClientProxy(object): +class ClientProxy: def __init__(self, client_pool): self.client_pool = client_pool @@ -62,7 +62,7 @@ class PooledMemcachedBackend(memcached_backend.MemcachedBackend): # Composed from GenericMemcachedBackend's and MemcacheArgs's __init__ def __init__(self, arguments): - super(PooledMemcachedBackend, self).__init__(arguments) + super().__init__(arguments) if arguments.get('sasl_enabled', False): if (arguments.get('username') is None or arguments.get('password') is None): diff --git a/oslo_cache/backends/mongo.py b/oslo_cache/backends/mongo.py index 15769b27..75fd99b9 100644 --- a/oslo_cache/backends/mongo.py +++ b/oslo_cache/backends/mongo.py @@ -211,7 +211,7 @@ class MongoCacheBackend(api.CacheBackend): self.client.delete_multi(keys) -class MongoApi(object): +class MongoApi: """Class handling MongoDB specific functionality. This class uses PyMongo APIs internally to create database connection @@ -494,7 +494,7 @@ class MongoApi(object): **self.meth_kwargs) -class AbstractManipulator(object, metaclass=abc.ABCMeta): +class AbstractManipulator(metaclass=abc.ABCMeta): """Abstract class with methods which need to be implemented for custom manipulation. diff --git a/oslo_cache/core.py b/oslo_cache/core.py index 4710cc13..329c7bb0 100644 --- a/oslo_cache/core.py +++ b/oslo_cache/core.py @@ -152,12 +152,12 @@ def _build_cache_config(conf): netloc = conf.cache.redis_server else: if conf.cache.redis_username: - netloc = '%s:%s@%s' % (conf.cache.redis_username, - conf.cache.redis_password, - conf.cache.redis_server) + netloc = '{}:{}@{}'.format(conf.cache.redis_username, + conf.cache.redis_password, + conf.cache.redis_server) else: - netloc = ':%s@%s' % (conf.cache.redis_password, - conf.cache.redis_server) + netloc = ':{}@{}'.format(conf.cache.redis_password, + conf.cache.redis_server) parts = urllib.parse.ParseResult( scheme=('rediss' if conf.cache.tls_enabled else 'redis'), diff --git a/oslo_cache/tests/functional/memcache_pool/test_cache_backend.py b/oslo_cache/tests/functional/memcache_pool/test_cache_backend.py index 9aca2afc..a31de075 100644 --- a/oslo_cache/tests/functional/memcache_pool/test_cache_backend.py +++ b/oslo_cache/tests/functional/memcache_pool/test_cache_backend.py @@ -29,7 +29,7 @@ class TestMemcachePoolCacheBackend(test_base.BaseTestCaseCacheBackend): # NOTE(hberaud): super must be called after all to ensure that # config fixture is properly initialized with value related to # the current backend in use. - super(TestMemcachePoolCacheBackend, self).setUp() + super().setUp() class TestBMemcachePoolCacheBackend(test_base.BaseTestCaseCacheBackend): @@ -46,4 +46,4 @@ class TestBMemcachePoolCacheBackend(test_base.BaseTestCaseCacheBackend): memcache_username='sasl_name', memcache_password='sasl_pswd' ) - super(TestBMemcachePoolCacheBackend, self).setUp() + super().setUp() diff --git a/oslo_cache/tests/test_cache.py b/oslo_cache/tests/test_cache.py index 6042dcd3..9cb0f532 100644 --- a/oslo_cache/tests/test_cache.py +++ b/oslo_cache/tests/test_cache.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright 2013 Metacloud # # Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -19,7 +18,7 @@ from oslotest import base class BaseTestCase(base.BaseTestCase): def setUp(self): - super(BaseTestCase, self).setUp() + super().setUp() self.config_fixture = self.useFixture(config_fixture.Config()) self.config_fixture.config( # TODO(morganfainberg): Make Cache Testing a separate test case diff --git a/oslo_cache/tests/unit/test_cache_backend_mongo.py b/oslo_cache/tests/unit/test_cache_backend_mongo.py index 2c176098..3c5b4c9d 100644 --- a/oslo_cache/tests/unit/test_cache_backend_mongo.py +++ b/oslo_cache/tests/unit/test_cache_backend_mongo.py @@ -62,10 +62,10 @@ SON_MANIPULATOR = None NO_VALUE = core.NO_VALUE -class MockCursor(object): +class MockCursor: def __init__(self, collection, dataset_factory): - super(MockCursor, self).__init__() + super().__init__() self.collection = collection self._factory = dataset_factory self._dataset = self._factory() @@ -94,10 +94,10 @@ class MockCursor(object): return arr[index] -class MockCollection(object): +class MockCollection: def __init__(self, db, name): - super(MockCollection, self).__init__() + super().__init__() self.name = name self._collection_database = db self._documents = {} @@ -218,7 +218,7 @@ class MockCollection(object): } -class MockMongoDB(object): +class MockMongoDB: def __init__(self, dbname): self._dbname = dbname @@ -243,7 +243,7 @@ class MockMongoDB(object): return get_collection(self._dbname, name) -class MockMongoClient(object): +class MockMongoClient: def __init__(self, *args, **kwargs): pass @@ -267,15 +267,15 @@ class MyTransformer(mongo.BaseTransform): """Added here just to check manipulator logic is used correctly.""" def transform_incoming(self, son, collection): - return super(MyTransformer, self).transform_incoming(son, collection) + return super().transform_incoming(son, collection) def transform_outgoing(self, son, collection): - return super(MyTransformer, self).transform_outgoing(son, collection) + return super().transform_outgoing(son, collection) class MongoCache(test_cache.BaseTestCase): def setUp(self): - super(MongoCache, self).setUp() + super().setUp() global COLLECTIONS COLLECTIONS = {} mongo.MongoApi._DB = {} @@ -417,7 +417,7 @@ class MongoCache(test_cache.BaseTestCase): self.assertIsInstance(region1.backend.api._data_manipulator, mongo.BaseTransform) - class_name = '%s.%s' % (MyTransformer.__module__, "MyTransformer") + class_name = '{}.{}'.format(MyTransformer.__module__, "MyTransformer") arguments2 = copy.copy(self.arguments) arguments2['cache_collection'] = 'cache_region2' diff --git a/oslo_cache/tests/unit/test_cache_basics.py b/oslo_cache/tests/unit/test_cache_basics.py index 28d469d5..e1c33bc8 100644 --- a/oslo_cache/tests/unit/test_cache_basics.py +++ b/oslo_cache/tests/unit/test_cache_basics.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Copyright 2013 Metacloud # # Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -50,7 +49,7 @@ class TestProxy(proxy.ProxyBackend): return value -class TestProxyValue(object): +class TestProxyValue: def __init__(self, value): self.value = value self.cached = False @@ -59,7 +58,7 @@ class TestProxyValue(object): class CacheRegionTest(test_cache.BaseTestCase): def setUp(self): - super(CacheRegionTest, self).setUp() + super().setUp() self.region = cache.create_region() cache.configure_cache_region(self.config_fixture.conf, self.region) self.region.wrap(TestProxy) @@ -110,7 +109,7 @@ class CacheRegionTest(test_cache.BaseTestCase): group='cache', expiration_group=TEST_GROUP2) - class _test_obj(object): + class _test_obj: def __init__(self, value): self.test_value = value diff --git a/oslo_cache/tests/unit/test_connection_pool.py b/oslo_cache/tests/unit/test_connection_pool.py index 5f2c7481..5ee89100 100644 --- a/oslo_cache/tests/unit/test_connection_pool.py +++ b/oslo_cache/tests/unit/test_connection_pool.py @@ -36,7 +36,7 @@ class _TestConnectionPool(_memcache_pool.ConnectionPool): class TestConnectionPool(test_cache.BaseTestCase): def setUp(self): - super(TestConnectionPool, self).setUp() + super().setUp() self.unused_timeout = 10 self.maxsize = 2 self.connection_pool = _TestConnectionPool( diff --git a/oslo_cache/tests/unit/test_dict_backend.py b/oslo_cache/tests/unit/test_dict_backend.py index be3ddb1a..1d39f27e 100644 --- a/oslo_cache/tests/unit/test_dict_backend.py +++ b/oslo_cache/tests/unit/test_dict_backend.py @@ -28,7 +28,7 @@ VALUE = 'test_value' class CacheDictBackendTest(test_cache.BaseTestCase): def setUp(self): - super(CacheDictBackendTest, self).setUp() + super().setUp() self.config_fixture = self.useFixture(config_fixture.Config()) self.config_fixture.config(group='cache', backend='oslo_cache.dict') self.time_fixture = self.useFixture(time_fixture.TimeFixture()) diff --git a/releasenotes/source/conf.py b/releasenotes/source/conf.py index 29f5c14f..cc0ef970 100644 --- a/releasenotes/source/conf.py +++ b/releasenotes/source/conf.py @@ -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