[英]How to properly line-wrap a django statement to satisfy flake8?
This code gets E501 line too long (85 > 79 characters)
from flake8: 这段代码从flake8获取
E501 line too long (85 > 79 characters)
:
qobjs &= Q(
latest_visit__visitstatistics__worst_zscore__gte=worst_zscore_min_filter)
This code gets E251 unexpected spaces around keyword / parameter equals
: 这段代码使
E251 unexpected spaces around keyword / parameter equals
:
qobjs &= Q(
latest_visit__visitstatistics__worst_zscore__gte=
worst_zscore_min_filter)
What is the right thing to satisfy flake8? 满足flake8的正确方法是什么?
EDIT : I ended up telling flake8 to ignore with noqa. 编辑 :我最终告诉flake8用noqa忽略。 I thought it didn't work, but I just had to read the docs more carefully.
我以为它不起作用,但是我只需要更仔细地阅读文档即可 。
Assuming you can't choose more sane variable names because these are machine generated, I wouldn't worry about it, and just tell pep8
(or pycodestyle
, or whatever flake8
is actually using to check for PEP-8 conformance) to ignore the line: 假设您不能选择更多的理智的变量名称,因为它们是机器生成的,我不会担心,只需告诉
pep8
(或pycodestyle
,或任何flake8
实际用于检查PEP-8一致性的flake8
)来忽略该行:
qobjs &= Q(...) # noqa
(Update: rather than ignore the line altogether, # noqa: E501
would let you ignore the line length, but still check for other problems.) (更新:
# noqa: E501
可以让您忽略# noqa: E501
,但仍要检查其他问题,而不是完全忽略行。)
If you are still using the default max line width of 79, consider using something longer. 如果仍使用默认的最大线宽79,请考虑使用更长的线。 PEP-8 really only requires that width for code in the standard library, and it explicitly states that teams may agree on a longer width.
PEP-8实际上只要求标准库中的代码具有该宽度,并且明确指出团队可能同意更长的宽度。
The error you are getting is because the newline after =
is counted as whitespace, as if you had typed Q(late...gte= worse...filter)
. 您得到的错误是因为
=
之后的换行符被计为空格,就像您键入Q(late...gte= worse...filter)
。 You could use explicit line continuation: 您可以使用显式的行继续:
qobjs &= Q(
latest_visit__visitstatistics__worst_zscore__gte=\
worst_zscore_min_filter)
or use shorter temporary names: 或使用较短的临时名称:
x = 'latest_visit__visitstatistics__worst_zscore__gte'
y = worst_zscore_min_filter
qobjs &= Q(**{x: y})
but my preference would be to just stop trying to appease flake8
on code that isn't supposed to be human-readable in the first place. 但我的选择是仅停止尝试
flake8
处理那些本来就不是人类可读的代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.