[英]Flake8 - line break before binary operator - how to fix it?
I keep getting:我不断得到:
W503 line break before binary operator
Please help me fix my code, as I can't figure out what is wrong here:请帮我修复我的代码,因为我无法弄清楚这里有什么问题:
def check_actionable(self, user_name, op, changes_table):
return any(user_name in row.inner_text() and row.query_selector(
self.OPS[op]) is not
None and row.query_selector(self.DISABLED) is not None for
row in changes_table)
W503 rule and W504 rule of flake8 are conflicted to each other. flake8 的 W503 规则和 W504 规则相互冲突。 I recommend you to add one of them into your
.flake8
's ignore list.我建议您将其中之一添加到您的
.flake8
的忽略列表中。
W503: line break before binary operator
W503:二元运算符前的换行符
W504: line break after binary operator
W504:二元运算符后的换行符
ignore = D400,D300,D205,D200,D105,D100,D101,D103,D107,W503,E712
The below code is prettified:下面的代码是美化的:
def check_actionable(self, user_name, op, changes_table):
return any(user_name in row.inner_text() and
row.query_selector(self.OPS[op]) is not None and
row.query_selector(self.DISABLED) is not None for row in changes_table)
Some explanation on W503 and W504:关于 W503 和 W504 的一些解释:
binary operator: +, -, /, and, or, ...
二元运算符:+, -, /, and, or, ...
To pass W503, your code should be like this:要通过 W503,您的代码应如下所示:
x = (1
+ 2)
To pass W504, your code should be like this:要通过 W504,您的代码应如下所示:
x = (1 +
2)
the other (imo better) alternative to ignore
(which resets the default ignore list) is to use extend-ignore
ignore
(重置默认忽略列表)的另一个(imo 更好)替代方法是使用extend-ignore
by default both W503
and W504
are ignored (as they conflict and have flip-flopped historically).默认情况下,
W503
和W504
都被忽略(因为它们发生冲突并且历史上曾发生过翻转)。 there are other rules which are ignored by default as well that you may want to preserve还有其他默认情况下会被忽略的规则,您可能希望保留这些规则
extend-ignore = ABC123
ignore
on the other hand resets the ignore list removing the defaults另一方面,
ignore
重置忽略列表,删除默认值
disclaimer: I'm the current flake8 maintainer免责声明:我是当前的 flake8 维护者
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.