From 3973fc393c203d424f48bfd04a96f9bf2d6929e1 Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Tue, 12 Dec 2023 18:31:30 +0000 Subject: [PATCH] Bump hacking version This bumps the version of flake8 and resolves some erroneous failures in f-strings. A number of new E721 (do not compare types) class errors are picked up, which are all addressed. Change-Id: I7a1937b107ff3af8d1e5fe23fc32b120ef4697f7 Signed-off-by: Stephen Finucane --- .pre-commit-config.yaml | 2 +- nova/compute/api.py | 2 +- nova/test.py | 4 ++-- nova/tests/fixtures/libvirt.py | 4 ++-- nova/tests/unit/compute/test_compute.py | 2 +- nova/tests/unit/virt/libvirt/test_driver.py | 6 +++--- nova/tests/unit/virt/test_hardware.py | 8 ++++---- nova/virt/libvirt/config.py | 2 +- nova/virt/libvirt/driver.py | 2 +- test-requirements.txt | 6 +----- 10 files changed, 17 insertions(+), 21 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7e72b7502db9..5e90b5df993d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -24,7 +24,7 @@ repos: - id: remove-tabs exclude: '.*\.(svg)$' - repo: https://opendev.org/openstack/hacking - rev: 6.0.1 + rev: 6.1.0 hooks: - id: hacking additional_dependencies: [] diff --git a/nova/compute/api.py b/nova/compute/api.py index 4b178a37a77a..bee8131a78d8 100644 --- a/nova/compute/api.py +++ b/nova/compute/api.py @@ -3390,7 +3390,7 @@ class API: "error_msg": str(exc)}) attr = 'task_state' state = task_states.DELETING - if type(ex) == exception.InstanceNotFound: + if type(ex) is exception.InstanceNotFound: attr = 'vm_state' state = vm_states.DELETED raise exception.InstanceInvalidState(attr=attr, diff --git a/nova/test.py b/nova/test.py index 90727043448c..1bee67c2176c 100644 --- a/nova/test.py +++ b/nova/test.py @@ -820,10 +820,10 @@ class MatchType(object): self.wanttype = wanttype def __eq__(self, other): - return type(other) == self.wanttype + return type(other) is self.wanttype def __ne__(self, other): - return type(other) != self.wanttype + return type(other) is not self.wanttype def __repr__(self): return "" diff --git a/nova/tests/fixtures/libvirt.py b/nova/tests/fixtures/libvirt.py index d668b59bcbbb..43890cd57a62 100644 --- a/nova/tests/fixtures/libvirt.py +++ b/nova/tests/fixtures/libvirt.py @@ -2157,10 +2157,10 @@ class Connection(object): def openAuth(uri, auth, flags=0): - if type(auth) != list: + if type(auth) is not list: raise Exception("Expected a list for 'auth' parameter") - if type(auth[0]) != list: + if type(auth[0]) is not list: raise Exception("Expected a function in 'auth[0]' parameter") if not callable(auth[1]): diff --git a/nova/tests/unit/compute/test_compute.py b/nova/tests/unit/compute/test_compute.py index f63082d951ea..28a7e168b4ff 100644 --- a/nova/tests/unit/compute/test_compute.py +++ b/nova/tests/unit/compute/test_compute.py @@ -12918,7 +12918,7 @@ class ComputeAPIAggrTestCase(BaseTestCase): self.aggr = aggr def __eq__(self, other_aggr): - if type(self.aggr) != type(other_aggr): + if type(self.aggr) is not type(other_aggr): return False return self.aggr.id == other_aggr.id diff --git a/nova/tests/unit/virt/libvirt/test_driver.py b/nova/tests/unit/virt/libvirt/test_driver.py index 601f29d38714..5e8bd598ecee 100644 --- a/nova/tests/unit/virt/libvirt/test_driver.py +++ b/nova/tests/unit/virt/libvirt/test_driver.py @@ -7727,7 +7727,7 @@ class LibvirtConnTestCase(test.NoDBTestCase, had_pci = 0 # care only about the PCI devices for dev in cfg.devices: - if type(dev) == vconfig.LibvirtConfigGuestHostdevPCI: + if type(dev) is vconfig.LibvirtConfigGuestHostdevPCI: had_pci += 1 self.assertEqual(dev.type, 'pci') self.assertEqual(dev.managed, 'yes') @@ -13473,7 +13473,7 @@ class LibvirtConnTestCase(test.NoDBTestCase, self.assertGreater(len(job_info_records), 0) rec = job_info_records.pop(0) - if type(rec) == str: + if type(rec) is str: if rec == "thread-finish": finish_event.send() elif rec == "domain-stop": @@ -14149,7 +14149,7 @@ class LibvirtConnTestCase(test.NoDBTestCase, class AnyEventletEvent(object): def __eq__(self, other): - return type(other) == eventlet.event.Event + return type(other) is eventlet.event.Event mock_thread.assert_called_once_with( drvr._live_migration_operation, diff --git a/nova/tests/unit/virt/test_hardware.py b/nova/tests/unit/virt/test_hardware.py index 11c8c7c748c2..ffecf4e38e97 100644 --- a/nova/tests/unit/virt/test_hardware.py +++ b/nova/tests/unit/virt/test_hardware.py @@ -399,7 +399,7 @@ class VCPUTopologyTest(test.NoDBTestCase): for topo_test in testdata: image_meta = objects.ImageMeta.from_dict(topo_test["image"]) - if type(topo_test["expect"]) == tuple: + if type(topo_test["expect"]) is tuple: (preferred, maximum) = hw.get_cpu_topology_constraints( topo_test["flavor"], image_meta) @@ -525,7 +525,7 @@ class VCPUTopologyTest(test.NoDBTestCase): ] for topo_test in testdata: - if type(topo_test["expect"]) == list: + if type(topo_test["expect"]) is list: actual = [] for topology in hw._get_possible_cpu_topologies( topo_test["vcpus"], @@ -1001,7 +1001,7 @@ class NUMATopologyTest(test.NoDBTestCase): cpu_policy = hw.get_cpu_policy_constraint( testitem["flavor"], image_meta) self.assertIsNone(cpu_policy) - elif type(testitem["expect"]) == type: + elif type(testitem["expect"]) is type: self.assertRaises(testitem["expect"], hw.get_cpu_policy_constraint, testitem["flavor"], @@ -1990,7 +1990,7 @@ class NUMATopologyTest(test.NoDBTestCase): topology = hw.numa_get_constraints( testitem["flavor"], image_meta) self.assertIsNone(topology) - elif type(testitem["expect"]) == type: + elif type(testitem["expect"]) is type: self.assertRaises(testitem["expect"], hw.numa_get_constraints, testitem["flavor"], diff --git a/nova/virt/libvirt/config.py b/nova/virt/libvirt/config.py index 0fb129c20b2d..42bd262d204e 100644 --- a/nova/virt/libvirt/config.py +++ b/nova/virt/libvirt/config.py @@ -269,7 +269,7 @@ class LibvirtConfigDomainCapsDevices(LibvirtConfigObject): def _get_device(self, device_type): for device in self.devices: - if type(device) == self.DEVICE_PARSERS.get(device_type): + if type(device) is self.DEVICE_PARSERS.get(device_type): return device return None diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py index 2be2ebc9ac6b..34c5d257560e 100644 --- a/nova/virt/libvirt/driver.py +++ b/nova/virt/libvirt/driver.py @@ -3114,7 +3114,7 @@ class LibvirtDriver(driver.ComputeDriver): purge_props=False) except (NotImplementedError, exception.ImageUnacceptable, exception.Forbidden) as e: - if type(e) != NotImplementedError: + if type(e) is not NotImplementedError: LOG.warning('Performing standard snapshot because direct ' 'snapshot failed: %(error)s', {'error': encodeutils.exception_to_unicode(e)}) diff --git a/test-requirements.txt b/test-requirements.txt index a5238bb96d96..04d228c916f6 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,8 +1,4 @@ -# The order of packages is significant, because pip processes them in the order -# of appearance. Changing the order has an impact on the overall integration -# process, which may cause wedges in the gate later. - -hacking>=6.0.1,<=6.0.1 # Apache-2.0 +hacking==6.1.0 # Apache-2.0 mypy>=0.761 # MIT types-paramiko>=0.1.3 # Apache-2.0 coverage!=4.4,>=4.0 # Apache-2.0