From 27808af1181851620cd54e310958cfbc54e20073 Mon Sep 17 00:00:00 2001 From: Andreas Jaeger Date: Wed, 1 Apr 2020 14:09:52 +0200 Subject: [PATCH] Hacking: Fix E731 Fix: E731 do not assign a lambda expression, use a def I just marked the lambdas with noqa. Fix also other problems found by hacking in files changed. Change-Id: I4e47670f5a96e61fba617e4cb9478958f7089711 --- .../1f0bd302c1a6_add_availability_zones_table.py | 2 +- manila/quota.py | 4 ++-- manila/share/drivers/glusterfs/layout_volume.py | 12 ++++++------ .../netapp/dataontap/cluster_mode/lib_base.py | 2 +- manila/share/drivers/windows/windows_smb_helper.py | 2 +- manila/test.py | 8 +++++--- manila/tests/scheduler/filters/test_base.py | 2 +- manila/tests/share/test_driver.py | 14 +++++++------- tox.ini | 3 +-- 9 files changed, 25 insertions(+), 24 deletions(-) diff --git a/manila/db/migrations/alembic/versions/1f0bd302c1a6_add_availability_zones_table.py b/manila/db/migrations/alembic/versions/1f0bd302c1a6_add_availability_zones_table.py index 2c06862158..c122cd7b4d 100644 --- a/manila/db/migrations/alembic/versions/1f0bd302c1a6_add_availability_zones_table.py +++ b/manila/db/migrations/alembic/versions/1f0bd302c1a6_add_availability_zones_table.py @@ -82,7 +82,7 @@ def upgrade(): # Map string AZ names to ID's in target tables # pylint: disable=no-value-for-parameter - set_az_id_in_table = lambda table, id, name: ( + set_az_id_in_table = lambda table, id, name: ( # noqa: E731 op.execute( table.update().where(table.c.availability_zone == name).values( {'availability_zone_id': id}) diff --git a/manila/quota.py b/manila/quota.py index 72ca8b101f..4279df6fab 100644 --- a/manila/quota.py +++ b/manila/quota.py @@ -346,9 +346,9 @@ class DbQuotaDriver(object): # Filter resources if has_sync: - sync_filt = lambda x: hasattr(x, 'sync') + sync_filt = lambda x: hasattr(x, 'sync') # noqa: E731 else: - sync_filt = lambda x: not hasattr(x, 'sync') + sync_filt = lambda x: not hasattr(x, 'sync') # noqa: E731 desired = set(keys) sub_resources = {k: v for k, v in resources.items() if k in desired and sync_filt(v)} diff --git a/manila/share/drivers/glusterfs/layout_volume.py b/manila/share/drivers/glusterfs/layout_volume.py index 818c5cf109..0b06c84f02 100644 --- a/manila/share/drivers/glusterfs/layout_volume.py +++ b/manila/share/drivers/glusterfs/layout_volume.py @@ -52,8 +52,8 @@ glusterfs_volume_mapped_opts = [ 'parameter which matches an integer (sequence of ' 'digits) in which case the value shall be interpreted as ' 'size of the volume in GB. Examples: ' - '"manila-share-volume-\d+$", ' - '"manila-share-volume-#{size}G-\d+$"; ' + r'"manila-share-volume-\d+$", ' + r'"manila-share-volume-#{size}G-\d+$"; ' 'with matching volume names, respectively: ' '"manila-share-volume-12", "manila-share-volume-3G-13". ' 'In latter example, the number that matches "#{size}", ' @@ -72,10 +72,10 @@ CONF.register_opts(glusterfs_volume_mapped_opts) # and a transformer function ('trans') for the matched # string value. # Currently we handle only #{size}. -PATTERN_DICT = {'size': {'pattern': '(?P\d+)', 'trans': int}} +PATTERN_DICT = {'size': {'pattern': r'(?P\d+)', 'trans': int}} USER_MANILA_SHARE = 'user.manila-share' USER_CLONED_FROM = 'user.manila-cloned-from' -UUID_RE = re.compile('\A[\da-f]{8}-([\da-f]{4}-){3}[\da-f]{12}\Z', re.I) +UUID_RE = re.compile(r'\A[\da-f]{8}-([\da-f]{4}-){3}[\da-f]{12}\Z', re.I) class GlusterfsVolumeMappedLayout(layout.GlusterfsShareLayoutBase): @@ -276,10 +276,10 @@ class GlusterfsVolumeMappedLayout(layout.GlusterfsShareLayoutBase): if size and 'size' in self.volume_pattern_keys: # then this function is used to extract the # size value for a given volume from the voldict... - get_volsize = lambda vol: voldict[vol]['size'] + get_volsize = lambda vol: voldict[vol]['size'] # noqa: E731 else: # else just use a stub. - get_volsize = lambda vol: None + get_volsize = lambda vol: None # noqa: E731 for vol in unused_vols: # For each unused volume, we extract the # and values with which it can be inserted diff --git a/manila/share/drivers/netapp/dataontap/cluster_mode/lib_base.py b/manila/share/drivers/netapp/dataontap/cluster_mode/lib_base.py index 3a508e4016..e872851bb4 100644 --- a/manila/share/drivers/netapp/dataontap/cluster_mode/lib_base.py +++ b/manila/share/drivers/netapp/dataontap/cluster_mode/lib_base.py @@ -919,7 +919,7 @@ class NetAppCmodeFileStorageLibrary(object): def _sort_export_locations_by_preferred_paths(self, export_locations): """Sort the export locations to report preferred paths first.""" - sort_key = lambda location: location.get( + sort_key = lambda location: location.get( # noqa: E731 'metadata', {}).get('preferred') is not True return sorted(export_locations, key=sort_key) diff --git a/manila/share/drivers/windows/windows_smb_helper.py b/manila/share/drivers/windows/windows_smb_helper.py index 8cb910ee7a..b96830f2fe 100644 --- a/manila/share/drivers/windows/windows_smb_helper.py +++ b/manila/share/drivers/windows/windows_smb_helper.py @@ -223,7 +223,7 @@ class WindowsSMBHelper(helpers.CIFSHelperBase): def _subtract_access_rules(self, access_rules, subtracted_rules): # Account names are case insensitive on Windows. - filter_rules = lambda rules: [ + filter_rules = lambda rules: [ # noqa: E731 {'access_to': access_rule['access_to'].lower(), 'access_level': access_rule['access_level'], 'access_type': access_rule['access_type']} diff --git a/manila/test.py b/manila/test.py index 7177c8a740..71768c0ecd 100644 --- a/manila/test.py +++ b/manila/test.py @@ -361,9 +361,11 @@ class TestCase(base_test.BaseTestCase): if k not in ignored_keys} def _assertEqualListsOfObjects(self, objs1, objs2, ignored_keys=None): - obj_to_dict = lambda o: self._dict_from_object(o, ignored_keys) - sort_key = lambda d: [d[k] for k in sorted(d)] - conv_and_sort = lambda obj: sorted(map(obj_to_dict, obj), key=sort_key) + obj_to_dict = lambda o: ( # noqa: E731 + self._dict_from_object(o, ignored_keys)) + sort_key = lambda d: [d[k] for k in sorted(d)] # noqa: E731 + conv_and_sort = lambda obj: ( # noqa: E731 + sorted(map(obj_to_dict, obj), key=sort_key)) self.assertEqual(conv_and_sort(objs1), conv_and_sort(objs2)) diff --git a/manila/tests/scheduler/filters/test_base.py b/manila/tests/scheduler/filters/test_base.py index 234236b20c..6cd4e03801 100644 --- a/manila/tests/scheduler/filters/test_base.py +++ b/manila/tests/scheduler/filters/test_base.py @@ -30,7 +30,7 @@ class TestBaseFilter(test.TestCase): filters = [1, 2, 3, 4] filter_properties = {'x': 'y'} - side_effect = lambda value, props: value in [2, 3] + side_effect = lambda value, props: value in [2, 3] # noqa: E731 self.mock_object(self.filter, '_filter_one', mock.Mock(side_effect=side_effect)) diff --git a/manila/tests/share/test_driver.py b/manila/tests/share/test_driver.py index d76e756915..53cd85d9e8 100644 --- a/manila/tests/share/test_driver.py +++ b/manila/tests/share/test_driver.py @@ -261,7 +261,7 @@ class ShareDriverTestCase(test.TestCase): def test_snapshot_support_exists(self): driver.CONF.set_default('driver_handles_share_servers', True) - fake_method = lambda *args, **kwargs: None + fake_method = lambda *args, **kwargs: None # noqa: E731 child_methods = { "create_snapshot": fake_method, "delete_snapshot": fake_method, @@ -292,7 +292,7 @@ class ShareDriverTestCase(test.TestCase): driver.CONF.set_default('driver_handles_share_servers', True) common_drv_methods, child_drv_methods = [ - {method_name: lambda *args, **kwargs: None + {method_name: lambda *args, **kwargs: None # noqa: E731 for method_name in method_names} for method_names in (common_drv_meth_names, child_drv_meth_names)] @@ -316,7 +316,7 @@ class ShareDriverTestCase(test.TestCase): ) def test_snapshot_support_absent(self, methods): driver.CONF.set_default('driver_handles_share_servers', True) - fake_method = lambda *args, **kwargs: None + fake_method = lambda *args, **kwargs: None # noqa: E731 child_methods = {} for method in methods: child_methods[method] = fake_method @@ -349,7 +349,7 @@ class ShareDriverTestCase(test.TestCase): def test_snapshot_support_exists_and_set_explicitly( self, snapshots_are_supported): driver.CONF.set_default('driver_handles_share_servers', True) - fake_method = lambda *args, **kwargs: None + fake_method = lambda *args, **kwargs: None # noqa: E731 child_methods = { "create_snapshot": fake_method, "delete_snapshot": fake_method, @@ -368,7 +368,7 @@ class ShareDriverTestCase(test.TestCase): def test_create_share_from_snapshot_support_exists(self): driver.CONF.set_default('driver_handles_share_servers', True) - fake_method = lambda *args, **kwargs: None + fake_method = lambda *args, **kwargs: None # noqa: E731 child_methods = { "create_share_from_snapshot": fake_method, "create_snapshot": fake_method, @@ -391,7 +391,7 @@ class ShareDriverTestCase(test.TestCase): ) def test_create_share_from_snapshot_support_absent(self, methods): driver.CONF.set_default('driver_handles_share_servers', True) - fake_method = lambda *args, **kwargs: None + fake_method = lambda *args, **kwargs: None # noqa: E731 child_methods = {} for method in methods: child_methods[method] = fake_method @@ -427,7 +427,7 @@ class ShareDriverTestCase(test.TestCase): def test_create_share_from_snapshot_exists_and_set_explicitly( self, create_share_from_snapshot_supported): driver.CONF.set_default('driver_handles_share_servers', True) - fake_method = lambda *args, **kwargs: None + fake_method = lambda *args, **kwargs: None # noqa: E731 child_methods = {"create_share_from_snapshot": fake_method} child_class_instance = type( "NotRedefined", (driver.ShareDriver, ), child_methods)(True) diff --git a/tox.ini b/tox.ini index 31b4f7cd68..e4fbac37df 100644 --- a/tox.ini +++ b/tox.ini @@ -134,8 +134,7 @@ commands = alembic -c manila/db/migrations/alembic.ini revision -m ""{posargs} # W503 line break before binary operator # W504 line break after binary operator # W605 invalid escape sequence -# E731 do not assign a lambda expression, use a def -ignore = E123,E402,E731,W503,W504,W605 +ignore = E123,E402,W503,W504,W605 builtins = _ # [H106] Don't put vim configuration in source files. # [H203] Use assertIs(Not)None to check for None.