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: Iee7efec960a0022c3976e0bf2a21fa4fa1ebe034
This commit is contained in:
parent
69923a1478
commit
344a7e151f
@ -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]
|
||||
|
@ -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
|
||||
|
@ -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):
|
||||
|
@ -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.
|
||||
|
||||
|
@ -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'),
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
|
@ -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'
|
||||
|
@ -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
|
||||
|
||||
|
@ -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(
|
||||
|
@ -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())
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user