From f4ac1e7b7dd1320c8f996bbefe147ccebf9a39e1 Mon Sep 17 00:00:00 2001 From: Yuxiang Zhu Date: Mar 04 2019 16:12:24 +0000 Subject: FIX W504 warning: Line break occurred after a binary operator After upgrading C3I Jenkins slave pod from Fedora 28 to 29, C3I pipeline builds for waiverdb fails with a Flake8 warning: [W504 line break after binary operator][2]. This happens because of a [updated PEP 8 rule][1], which recommends that line breaks should occur before the binary operator because it keeps all operators aligned. However [both W503 and W504 are enforced when all warnings are configured][3]. This pull-request eliminates the warning by following the new rule and ignoring W503. [1]: https://www.python.org/dev/peps/pep-0008/#should-a-line-break-before-or-after-a-binary-operator [2]: https://lintlyci.github.io/Flake8Rules/rules/W504.html [3]: https://gitlab.com/pycqa/flake8/issues/463 --- diff --git a/tests/test_monitor.py b/tests/test_monitor.py index 19d0c6b..7ee8317 100644 --- a/tests/test_monitor.py +++ b/tests/test_monitor.py @@ -13,11 +13,11 @@ def test_metrics(client): assert r.status_code == 200 assert len([l for l in r.get_data(as_text=True).splitlines() - if l.startswith('# TYPE messaging_') and - l.endswith(' counter')]) == 4 + if l.startswith('# TYPE messaging_') + and l.endswith(' counter')]) == 4 assert len([l for l in r.get_data(as_text=True).splitlines() - if l.startswith('# TYPE db_') and - l.endswith(' counter')]) == 4 + if l.startswith('# TYPE db_') + and l.endswith(' counter')]) == 4 def test_standalone_metrics_server_disabled_by_default(): @@ -32,8 +32,8 @@ def test_standalone_metrics_server(): r = requests.get('http://127.0.0.1:10040/metrics') assert len([l for l in r.text.splitlines() - if l.startswith('# TYPE messaging_') and - l.endswith(' counter')]) == 4 + if l.startswith('# TYPE messaging_') + and l.endswith(' counter')]) == 4 assert len([l for l in r.text.splitlines() - if l.startswith('# TYPE db_') and - l.endswith(' counter')]) == 4 + if l.startswith('# TYPE db_') + and l.endswith(' counter')]) == 4 diff --git a/tox.ini b/tox.ini index 1f0089f..0256e61 100644 --- a/tox.ini +++ b/tox.ini @@ -45,4 +45,5 @@ max-line-length = 100 exclude = .git,.tox,dist,*egg,env_waiverdb,*fedmsg.d,docs,conf,waiverdb/migrations # E124: closing bracket does not match visual indentation -ignore = E124 +# W503 line break before binary operator +ignore = E124, W503 diff --git a/waiverdb/models/waivers.py b/waiverdb/models/waivers.py index e59005e..bd5a1ac 100644 --- a/waiverdb/models/waivers.py +++ b/waiverdb/models/waivers.py @@ -12,9 +12,9 @@ def subject_dict_to_type_identifier(subject): This maps from the old style to the new, for backwards compatibility. """ # handling the special cases... - if (subject.get('type') in ['koji_build', 'brew-build'] and - 'item' in subject and - isinstance(subject['item'], str)): + if (subject.get('type') in ['koji_build', 'brew-build'] + and 'item' in subject + and isinstance(subject['item'], str)): return ('koji_build', subject['item']) elif 'original_spec_nvr' in subject and isinstance(subject['original_spec_nvr'], str): return ('koji_build', subject['original_spec_nvr'])