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
This commit is contained in:
Andreas Jaeger 2018-10-26 08:08:46 +02:00 committed by Felipe Monteiro
parent b170daeea7
commit cb737354f0
6 changed files with 13 additions and 8 deletions

View File

@ -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 '

View File

@ -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))

View File

@ -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))

View File

@ -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

View File

@ -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)

View File

@ -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