From cb737354f07ec81ac6bf564df3cbd02146ccc44f Mon Sep 17 00:00:00 2001 From: Andreas Jaeger Date: Fri, 26 Oct 2018 08:08:46 +0200 Subject: [PATCH] Fix Flake8 3.6.0 errors Flake8 3.6.0 now warns about both line break after and *before* binary operator, you have to choose whether you use W503 or W504. Disable the newer W504. Fix "F841 local variable 'e' is assigned to but never used". Handle warnings about invalid escape sequence in regex. Handle invalid escape sequence in string. Change-Id: I68efbde4e9dd2e6e9455d91313eb45c9c79d35ce --- armada/common/policy.py | 4 ++-- armada/handlers/document.py | 2 +- armada/handlers/wait.py | 2 +- armada/tests/unit/handlers/test_chartbuilder.py | 5 +++-- armada/tests/unit/handlers/test_override.py | 3 ++- tox.ini | 5 ++++- 6 files changed, 13 insertions(+), 8 deletions(-) diff --git a/armada/common/policy.py b/armada/common/policy.py index 5150543e..87ba7874 100644 --- a/armada/common/policy.py +++ b/armada/common/policy.py @@ -52,11 +52,11 @@ def _enforce_policy(action, target, credentials, do_raise=True): try: _ENFORCER.authorize(action, target, credentials.to_policy_view(), **extras) - except policy.PolicyNotRegistered as e: + except policy.PolicyNotRegistered: LOG.exception('Policy not registered for %(action)s', {'action': action}) raise exc.ActionForbidden() - except Exception as e: + except Exception: with excutils.save_and_reraise_exception(): LOG.debug( 'Policy check for %(action)s failed with credentials ' diff --git a/armada/handlers/document.py b/armada/handlers/document.py index 64e7c017..3039ff15 100644 --- a/armada/handlers/document.py +++ b/armada/handlers/document.py @@ -120,7 +120,7 @@ class ReferenceResolver(object): reference """ ks_sess = ks_utils.get_keystone_session() - (new_scheme, foo) = re.subn('^[^+]+\+', '', design_uri.scheme) + (new_scheme, foo) = re.subn('^[^+]+\+', '', design_uri.scheme) # noqa url = urllib.parse.urlunparse( (new_scheme, design_uri.netloc, design_uri.path, design_uri.params, design_uri.query, design_uri.fragment)) diff --git a/armada/handlers/wait.py b/armada/handlers/wait.py index ed9fda37..a1312657 100644 --- a/armada/handlers/wait.py +++ b/armada/handlers/wait.py @@ -115,7 +115,7 @@ class ChartWait(): return DaemonSetWait(resource_type, self, labels, **kwargs) elif resource_type == 'statefulset': return StatefulSetWait(resource_type, self, labels, **kwargs) - except TypeError as e: + except TypeError: raise manifest_exceptions.ManifestException( 'invalid config for item in `wait.resources`: {}'.format( resource_config)) diff --git a/armada/tests/unit/handlers/test_chartbuilder.py b/armada/tests/unit/handlers/test_chartbuilder.py index 0d99d867..1b803f13 100644 --- a/armada/tests/unit/handlers/test_chartbuilder.py +++ b/armada/tests/unit/handlers/test_chartbuilder.py @@ -461,8 +461,9 @@ class ChartBuilderNegativeTestCase(BaseChartBuilderTestCase): chartbuilder = ChartBuilder(test_chart) # Confirm it failed for both encodings. - error_re = (r'.*A str exception occurred while trying to read file:' - '.*Details:\n.*\(encoding=utf-8\).*\n\(encoding=latin1\)') + error_re = ( + r'.*A str exception occurred while trying to read file:' # noqa + '.*Details:\n.*\(encoding=utf-8\).*\n\(encoding=latin1\)') with mock.patch("builtins.open", mock.mock_open(read_data="")) \ as mock_file: mock_file.return_value.read.side_effect = self.exc_to_raise diff --git a/armada/tests/unit/handlers/test_override.py b/armada/tests/unit/handlers/test_override.py index 62edaafa..ded286a9 100644 --- a/armada/tests/unit/handlers/test_override.py +++ b/armada/tests/unit/handlers/test_override.py @@ -322,7 +322,8 @@ class OverrideNegativeTestCase(testtools.TestCase): with open(self.base_manifest) as f: original_documents = list(yaml.safe_load_all(f.read())) - override = ('manifest:simple-armada:release_prefix=' '\overridden', ) + # Provide invalid JSON to compel the error to get thrown. + override = ('manifest:simple-armada:release_prefix=\\overridden', ) ovr = Override(original_documents, override) self.assertRaises(json.decoder.JSONDecodeError, ovr.update_manifests) diff --git a/tox.ini b/tox.ini index 2cb7cd14..4e10126e 100644 --- a/tox.ini +++ b/tox.ini @@ -102,5 +102,8 @@ commands = [flake8] filename = *.py -ignore = +# These are ignored intentionally: +# W504 - line break after binary operator, we cannot have both +# W503 and W504 enabled +ignore = W504 exclude = .git,.tox,dist,*lib/python*,*egg,build,releasenotes,doc/*,hapi,venv