diff --git a/examples/connect.py b/examples/connect.py index 1d4b86ad8..09a9cbef1 100644 --- a/examples/connect.py +++ b/examples/connect.py @@ -36,7 +36,7 @@ config = loader.OpenStackConfig() cloud = openstack.connect(cloud=TEST_CLOUD) -class Opts(object): +class Opts: def __init__(self, cloud_name='devstack-admin', debug=False): self.cloud = cloud_name self.debug = debug diff --git a/openstack/_services_mixin.py b/openstack/_services_mixin.py index eb58e83b8..75c1d19e7 100644 --- a/openstack/_services_mixin.py +++ b/openstack/_services_mixin.py @@ -20,7 +20,7 @@ from openstack.orchestration import orchestration_service from openstack.workflow import workflow_service -class ServicesMixin(object): +class ServicesMixin: identity = identity_service.IdentityService(service_type='identity') diff --git a/openstack/baremetal/v1/_common.py b/openstack/baremetal/v1/_common.py index 8fcf7b579..e37c7b73a 100644 --- a/openstack/baremetal/v1/_common.py +++ b/openstack/baremetal/v1/_common.py @@ -68,7 +68,7 @@ CONFIG_DRIVE_DICT_VERSION = '1.56' """API version in which configdrive can be a dictionary.""" -class ListMixin(object): +class ListMixin: @classmethod def list(cls, session, details=False, **params): diff --git a/openstack/baremetal/v1/node.py b/openstack/baremetal/v1/node.py index 5c034e723..8ef4edff4 100644 --- a/openstack/baremetal/v1/node.py +++ b/openstack/baremetal/v1/node.py @@ -18,7 +18,7 @@ from openstack import resource from openstack import utils -class ValidationResult(object): +class ValidationResult: """Result of a single interface validation. :ivar result: Result of a validation, ``True`` for success, ``False`` for diff --git a/openstack/cloud/_normalize.py b/openstack/cloud/_normalize.py index 97a27fa0b..4cbcd9f85 100644 --- a/openstack/cloud/_normalize.py +++ b/openstack/cloud/_normalize.py @@ -139,7 +139,7 @@ def _pop_or_get(resource, key, default, strict): return resource.get(key, default) -class Normalizer(object): +class Normalizer: '''Mix-in class to provide the normalization functions. This is in a separate class just for on-disk source code organization diff --git a/openstack/cloud/_utils.py b/openstack/cloud/_utils.py index 9a6a8cf0b..bb82a165b 100644 --- a/openstack/cloud/_utils.py +++ b/openstack/cloud/_utils.py @@ -667,7 +667,7 @@ def generate_patches_from_kwargs(operation, **kwargs): return sorted(patches) -class FileSegment(object): +class FileSegment: """File-like object to pass to requests.""" def __init__(self, filename, offset, length): diff --git a/openstack/cloud/inventory.py b/openstack/cloud/inventory.py index 8905ce0a7..32a26821b 100644 --- a/openstack/cloud/inventory.py +++ b/openstack/cloud/inventory.py @@ -22,7 +22,7 @@ from openstack.cloud import _utils __all__ = ['OpenStackInventory'] -class OpenStackInventory(object): +class OpenStackInventory: # Put this here so the capability can be detected with hasattr on the class extra_config = None diff --git a/openstack/cloud/openstackcloud.py b/openstack/cloud/openstackcloud.py index 2e821238a..fefdd9ba1 100755 --- a/openstack/cloud/openstackcloud.py +++ b/openstack/cloud/openstackcloud.py @@ -48,7 +48,7 @@ DEFAULT_MAX_FILE_SIZE = _object_store.DEFAULT_MAX_FILE_SIZE OBJECT_CONTAINER_ACLS = _object_store.OBJECT_CONTAINER_ACLS -class _OpenStackCloudMixin(object): +class _OpenStackCloudMixin: """Represent a connection to an OpenStack Cloud. OpenStackCloud is the entry point for all cloud operations, regardless @@ -126,7 +126,7 @@ class _OpenStackCloudMixin(object): def _fake_invalidate(unused): pass - class _FakeCache(object): + class _FakeCache: def invalidate(self): pass diff --git a/openstack/compute/v2/metadata.py b/openstack/compute/v2/metadata.py index 906dc7213..0d8ad2f12 100644 --- a/openstack/compute/v2/metadata.py +++ b/openstack/compute/v2/metadata.py @@ -15,7 +15,7 @@ from openstack import exceptions from openstack import utils -class MetadataMixin(object): +class MetadataMixin: def _metadata(self, method, key=None, clear=False, delete=False, metadata=None): diff --git a/openstack/config/_util.py b/openstack/config/_util.py index cdd6737e8..c77aaf235 100644 --- a/openstack/config/_util.py +++ b/openstack/config/_util.py @@ -45,7 +45,7 @@ def merge_clouds(old_dict, new_dict): return ret -class VersionRequest(object): +class VersionRequest: def __init__( self, version=None, diff --git a/openstack/config/cloud_region.py b/openstack/config/cloud_region.py index 41bcc9d5d..8f03d5386 100644 --- a/openstack/config/cloud_region.py +++ b/openstack/config/cloud_region.py @@ -201,7 +201,7 @@ def from_conf(conf, session=None, service_types=None, **kwargs): session=session, config=config_dict, **kwargs) -class CloudRegion(object): +class CloudRegion: # TODO(efried): Doc the rest of the kwargs """The configuration for a Region of an OpenStack Cloud. diff --git a/openstack/config/loader.py b/openstack/config/loader.py index 09e916c37..a86433f31 100644 --- a/openstack/config/loader.py +++ b/openstack/config/loader.py @@ -127,7 +127,7 @@ def _fix_argv(argv): options=','.join(overlap))) -class OpenStackConfig(object): +class OpenStackConfig: # These two attribute are to allow os-client-config to plumb in its # local versions for backwards compat. diff --git a/openstack/format.py b/openstack/format.py index 94fd310fe..7e586709d 100644 --- a/openstack/format.py +++ b/openstack/format.py @@ -11,7 +11,7 @@ # under the License. -class Formatter(object): +class Formatter: @classmethod def serialize(cls, value): diff --git a/openstack/image/_download.py b/openstack/image/_download.py index 0c50bffb2..21c6ffe77 100644 --- a/openstack/image/_download.py +++ b/openstack/image/_download.py @@ -24,7 +24,7 @@ def _verify_checksum(md5, checksum): "checksum mismatch: %s != %s" % (checksum, digest)) -class DownloadMixin(object): +class DownloadMixin: def download(self, session, stream=False, output=None, chunk_size=1024): """Download the data contained in an image""" diff --git a/openstack/image/image_signer.py b/openstack/image/image_signer.py index 19c6ec965..23d294811 100644 --- a/openstack/image/image_signer.py +++ b/openstack/image/image_signer.py @@ -28,7 +28,7 @@ HASH_METHODS = { } -class ImageSigner(object): +class ImageSigner: """Image file signature generator. Generates signatures for files using a specified private key file. diff --git a/openstack/image/iterable_chunked_file.py b/openstack/image/iterable_chunked_file.py index d887ace5b..3b9d9569d 100644 --- a/openstack/image/iterable_chunked_file.py +++ b/openstack/image/iterable_chunked_file.py @@ -12,7 +12,7 @@ # -class IterableChunkedFile(object): +class IterableChunkedFile: """File object chunk iterator using yield. Represents a local file as an iterable object by splitting the file diff --git a/openstack/resource.py b/openstack/resource.py index cf9d9a476..b102549a4 100644 --- a/openstack/resource.py +++ b/openstack/resource.py @@ -82,7 +82,7 @@ def _convert_type(value, data_type, list_type=None): return data_type(value) -class _BaseComponent(object): +class _BaseComponent: # The name this component is being tracked as in the Resource key = None @@ -257,7 +257,7 @@ class _ComponentManager(collections.MutableMapping): self._dirty = set() -class _Request(object): +class _Request: """Prepared components that go into a KSA request""" def __init__(self, url, body, headers): @@ -266,7 +266,7 @@ class _Request(object): self.headers = headers -class QueryParameters(object): +class QueryParameters: def __init__(self, *names, **mappings): """Create a dict of accepted query parameters @@ -1862,7 +1862,7 @@ class Resource(dict): "No %s found for %s" % (cls.__name__, name_or_id)) -class TagMixin(object): +class TagMixin: _tag_query_parameters = { 'tags': 'tags', diff --git a/openstack/service_description.py b/openstack/service_description.py index 2aad61a6d..223a166d3 100644 --- a/openstack/service_description.py +++ b/openstack/service_description.py @@ -27,7 +27,7 @@ _logger = _log.setup_logging('openstack') _service_type_manager = os_service_types.ServiceTypes() -class _ServiceDisabledProxyShim(object): +class _ServiceDisabledProxyShim: def __init__(self, service_type, reason): self.service_type = service_type self.reason = reason @@ -39,7 +39,7 @@ class _ServiceDisabledProxyShim(object): service_type=self.service_type, reason=self.reason or '')) -class ServiceDescription(object): +class ServiceDescription: #: Dictionary of supported versions and proxy classes for that version supported_versions = None diff --git a/openstack/tests/fakes.py b/openstack/tests/fakes.py index 9fae3c7f5..af1bbe235 100644 --- a/openstack/tests/fakes.py +++ b/openstack/tests/fakes.py @@ -282,7 +282,7 @@ def make_fake_port(address, node_id=None, port_id=None): node_id=node_id)) -class FakeFloatingIP(object): +class FakeFloatingIP: def __init__(self, id, pool, ip, fixed_ip, instance_id): self.id = id self.pool = pool @@ -345,7 +345,7 @@ def make_fake_hypervisor(id, name): })) -class FakeVolume(object): +class FakeVolume: def __init__( self, id, status, name, attachments=[], size=75): @@ -363,7 +363,7 @@ class FakeVolume(object): self.metadata = {} -class FakeVolumeSnapshot(object): +class FakeVolumeSnapshot: def __init__( self, id, status, name, description, size=75): self.id = id @@ -376,7 +376,7 @@ class FakeVolumeSnapshot(object): self.metadata = {} -class FakeMachine(object): +class FakeMachine: def __init__(self, id, name=None, driver=None, driver_info=None, chassis_uuid=None, instance_info=None, instance_uuid=None, properties=None, reservation=None, last_error=None, @@ -394,7 +394,7 @@ class FakeMachine(object): self.provision_state = provision_state -class FakeMachinePort(object): +class FakeMachinePort: def __init__(self, id, address, node_id): self.uuid = id self.address = address @@ -443,7 +443,7 @@ def make_fake_nova_security_group(id, name, description, rules): })) -class FakeNovaSecgroupRule(object): +class FakeNovaSecgroupRule: def __init__(self, id, from_port=None, to_port=None, ip_protocol=None, cidr=None, parent_group_id=None): self.id = id @@ -455,13 +455,13 @@ class FakeNovaSecgroupRule(object): self.parent_group_id = parent_group_id -class FakeHypervisor(object): +class FakeHypervisor: def __init__(self, id, hostname): self.id = id self.hypervisor_hostname = hostname -class FakeZone(object): +class FakeZone: def __init__(self, id, name, type_, email, description, ttl, masters): self.id = id @@ -473,7 +473,7 @@ class FakeZone(object): self.masters = masters -class FakeRecordset(object): +class FakeRecordset: def __init__(self, zone, id, name, type_, description, ttl, records): self.zone = zone diff --git a/openstack/tests/functional/image/v2/test_image.py b/openstack/tests/functional/image/v2/test_image.py index badd31fc5..3635b6a72 100644 --- a/openstack/tests/functional/image/v2/test_image.py +++ b/openstack/tests/functional/image/v2/test_image.py @@ -18,7 +18,7 @@ TEST_IMAGE_NAME = 'Test Image' class TestImage(base.BaseFunctionalTest): - class ImageOpts(object): + class ImageOpts: def __init__(self): self.image_api_version = '2' diff --git a/openstack/tests/unit/cloud/test_meta.py b/openstack/tests/unit/cloud/test_meta.py index 0de6620d3..e925c63dd 100644 --- a/openstack/tests/unit/cloud/test_meta.py +++ b/openstack/tests/unit/cloud/test_meta.py @@ -24,13 +24,13 @@ PUBLIC_V4 = '192.0.2.99' PUBLIC_V6 = '2001:0db8:face:0da0:face::0b00:1c' # rfc3849 -class FakeConfig(object): +class FakeConfig: def get_region_name(self, service_type=None): # TODO(efried): Validate service_type? return 'test-region' -class FakeCloud(object): +class FakeCloud: config = FakeConfig() name = 'test-name' private = False @@ -942,10 +942,10 @@ class TestMeta(base.TestCase): def test_obj_list_to_munch(self): """Test conversion of a list of objects to a list of dictonaries""" - class obj0(object): + class obj0: value = 0 - class obj1(object): + class obj1: value = 1 list = [obj0, obj1] diff --git a/openstack/tests/unit/cloud/test_zone.py b/openstack/tests/unit/cloud/test_zone.py index 3bea3fb71..145e04a26 100644 --- a/openstack/tests/unit/cloud/test_zone.py +++ b/openstack/tests/unit/cloud/test_zone.py @@ -26,7 +26,7 @@ zone_dict = { } -class ZoneTestWrapper(object): +class ZoneTestWrapper: def __init__(self, ut, attrs): self.remote_res = attrs diff --git a/openstack/tests/unit/compute/v2/test_server.py b/openstack/tests/unit/compute/v2/test_server.py index 6baf3c45c..e48266d8e 100644 --- a/openstack/tests/unit/compute/v2/test_server.py +++ b/openstack/tests/unit/compute/v2/test_server.py @@ -806,7 +806,7 @@ class TestServer(base.TestCase): def test_live_migrate_no_force(self): sot = server.Server(**EXAMPLE) - class FakeEndpointData(object): + class FakeEndpointData: min_microversion = None max_microversion = None self.sess.get_endpoint_data.return_value = FakeEndpointData() @@ -822,7 +822,7 @@ class TestServer(base.TestCase): def test_live_migrate_no_microversion_force_true(self): sot = server.Server(**EXAMPLE) - class FakeEndpointData(object): + class FakeEndpointData: min_microversion = None max_microversion = None self.sess.get_endpoint_data.return_value = FakeEndpointData() @@ -848,7 +848,7 @@ class TestServer(base.TestCase): def test_live_migrate_25(self): sot = server.Server(**EXAMPLE) - class FakeEndpointData(object): + class FakeEndpointData: min_microversion = '2.1' max_microversion = '2.25' self.sess.get_endpoint_data.return_value = FakeEndpointData() @@ -872,7 +872,7 @@ class TestServer(base.TestCase): def test_live_migrate_25_default_block(self): sot = server.Server(**EXAMPLE) - class FakeEndpointData(object): + class FakeEndpointData: min_microversion = '2.1' max_microversion = '2.25' self.sess.get_endpoint_data.return_value = FakeEndpointData() @@ -896,7 +896,7 @@ class TestServer(base.TestCase): def test_live_migrate_30(self): sot = server.Server(**EXAMPLE) - class FakeEndpointData(object): + class FakeEndpointData: min_microversion = '2.1' max_microversion = '2.30' self.sess.get_endpoint_data.return_value = FakeEndpointData() @@ -920,7 +920,7 @@ class TestServer(base.TestCase): def test_live_migrate_30_force(self): sot = server.Server(**EXAMPLE) - class FakeEndpointData(object): + class FakeEndpointData: min_microversion = '2.1' max_microversion = '2.30' self.sess.get_endpoint_data.return_value = FakeEndpointData() diff --git a/openstack/tests/unit/image/v2/test_image.py b/openstack/tests/unit/image/v2/test_image.py index 4bc95baf6..0086c640f 100644 --- a/openstack/tests/unit/image/v2/test_image.py +++ b/openstack/tests/unit/image/v2/test_image.py @@ -95,7 +95,7 @@ def calculate_md5_checksum(data): return checksum.hexdigest() -class FakeResponse(object): +class FakeResponse: def __init__(self, response, status_code=200, headers=None, reason=None): self.body = response self.content = response diff --git a/openstack/tests/unit/image/v2/test_proxy.py b/openstack/tests/unit/image/v2/test_proxy.py index 20e35d750..5392c7381 100644 --- a/openstack/tests/unit/image/v2/test_proxy.py +++ b/openstack/tests/unit/image/v2/test_proxy.py @@ -27,7 +27,7 @@ from openstack.tests.unit import test_proxy_base EXAMPLE = fake_image.EXAMPLE -class FakeResponse(object): +class FakeResponse: def __init__(self, response, status_code=200, headers=None): self.body = response self.status_code = status_code diff --git a/openstack/tests/unit/test_proxy.py b/openstack/tests/unit/test_proxy.py index 46c9ff8be..3cd7b0ed2 100644 --- a/openstack/tests/unit/test_proxy.py +++ b/openstack/tests/unit/test_proxy.py @@ -137,7 +137,7 @@ class TestProxyPrivate(base.TestCase): # of that same behavior to let us check that `new` gets # called with the expected arguments. - class Fake(object): + class Fake: call = {} @classmethod diff --git a/openstack/tests/unit/test_resource.py b/openstack/tests/unit/test_resource.py index 6d327a1a8..67fd7c863 100644 --- a/openstack/tests/unit/test_resource.py +++ b/openstack/tests/unit/test_resource.py @@ -24,7 +24,7 @@ from openstack import resource from openstack.tests.unit import base -class FakeResponse(object): +class FakeResponse: def __init__(self, response, status_code=200, headers=None): self.body = response self.status_code = status_code @@ -74,7 +74,7 @@ class TestComponent(base.TestCase): def test_get_name_None(self): name = "name" - class Parent(object): + class Parent: _example = {name: None} instance = Parent() @@ -87,7 +87,7 @@ class TestComponent(base.TestCase): def test_get_default(self): expected_result = 123 - class Parent(object): + class Parent: _example = {} instance = Parent() @@ -104,7 +104,7 @@ class TestComponent(base.TestCase): name = "name" expected_result = 123 - class Parent(object): + class Parent: _example = {name: expected_result} instance = Parent() @@ -119,7 +119,7 @@ class TestComponent(base.TestCase): name = "name" value = "123" - class Parent(object): + class Parent: _example = {name: value} instance = Parent() @@ -134,7 +134,7 @@ class TestComponent(base.TestCase): value = "123" expected_result = "one hundred twenty three" - class Parent(object): + class Parent: _example = {name: value} class FakeFormatter(format.Formatter): @@ -154,7 +154,7 @@ class TestComponent(base.TestCase): name = "name" expected_value = "123" - class Parent(object): + class Parent: _example = {} instance = Parent() @@ -167,7 +167,7 @@ class TestComponent(base.TestCase): def test_set_name_typed(self): expected_value = "123" - class Parent(object): + class Parent: _example = {} instance = Parent() @@ -177,7 +177,7 @@ class TestComponent(base.TestCase): # instance that would allow us to call `assert_called_once_with` to # ensure that we're sending the value through the type. # Instead, we use this tiny version of a similar thing. - class FakeType(object): + class FakeType: calls = [] def __init__(self, arg): @@ -192,7 +192,7 @@ class TestComponent(base.TestCase): def test_set_name_formatter(self): expected_value = "123" - class Parent(object): + class Parent: _example = {} instance = Parent() @@ -220,7 +220,7 @@ class TestComponent(base.TestCase): name = "name" expected_value = "123" - class Parent(object): + class Parent: _example = {name: expected_value} instance = Parent() @@ -235,7 +235,7 @@ class TestComponent(base.TestCase): name = "name" expected_value = "123" - class Parent(object): + class Parent: _example = {"what": expected_value} instance = Parent() diff --git a/openstack/utils.py b/openstack/utils.py index d893d6fc0..962113fd7 100644 --- a/openstack/utils.py +++ b/openstack/utils.py @@ -75,7 +75,7 @@ def get_string_format_keys(fmt_string, old_style=True): use the old style string formatting. """ if old_style: - class AccessSaver(object): + class AccessSaver: def __init__(self): self.keys = [] @@ -192,7 +192,7 @@ def maximum_supported_microversion(adapter, client_maximum): return discover.version_to_string(result) -class TinyDAG(object): +class TinyDAG: """Tiny DAG Bases on the Kahn's algorithm, and enables parallel visiting of the nodes diff --git a/tools/print-services.py b/tools/print-services.py index b4c664957..73dd3d09f 100644 --- a/tools/print-services.py +++ b/tools/print-services.py @@ -71,7 +71,7 @@ def make_names(): for imp in sorted(imports): print(imp) print('\n') - print("class ServicesMixin(object):\n") + print("class ServicesMixin:\n") for service in services: if service: print(" {service}".format(service=service)) diff --git a/tox.ini b/tox.ini index 3e6f1bfd0..e8809b843 100644 --- a/tox.ini +++ b/tox.ini @@ -107,12 +107,13 @@ commands = # The following are ignored on purpose. It's not super worth it to fix them. # However, if you feel strongly about it, patches will be accepted to fix them # if they fix ALL of the occurances of one and only one of them. +# H238 New Style Classes are the default in Python3 # H306 Is about alphabetical imports - there's a lot to fix. # H4 Are about docstrings and there's just a huge pile of pre-existing issues. # W503 Is supposed to be off by default but in the latest pycodestyle isn't. # Also, both openstacksdk and Donald Knuth disagree with the rule. Line # breaks should occur before the binary operator for readability. -ignore = H306,H4,W503 +ignore = H238,H306,H4,W503 show-source = True exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build,openstack/_services_mixin.py