我已经开始使用Flake8检查我的python代码,但是它总是给我一个错误/警告--我觉得排序很痛苦--是“缩进/缩进的继续行”。
Flake8希望我的延拓行与起始括号完全对齐。因此,在下面的示例中,Flake8不喜欢前两个,但喜欢第三个:(?)=4个空格,·=单个空格)
let_us_pass.some_function(with_a_lot_of=['strings'], or_other_arguments,
» » » » » » and_another)
let_us_pass.some_function(with_a_lot_of=['strings'], or_other_arguments,
» » » » » » » and_another)
let_us_pass.some_function(with_a_lot_of=['strings'], or_other_arguments,
» » » » » » ··and_another)
因此,Flake8不会抱怨混合了4个空间块和单个空间。
我在PEP8中所能找到的只有一个例子中的注释:# Hanging indents *may* be indented to other than 4 spaces.
这是不是意味着它被皱眉头了?我应该坚持清除所有Flake8警告(并混合空格数),还是接受警告以保持4空间的纯度。
发布于 2018-10-18 12:49:06
引用相关PEP8页面的脚注:
悬挂式缩进是一种类型设置样式,除第一行外,段落中的所有行都是缩进的。在Python上下文中,该术语用于描述一种样式,其中括号大小语句的开始括号是该行的最后一个非空格字符,随后的行被缩进,直到结束括号。
# Hanging indents *may* be indented to other than 4 spaces.
foo = long_function_name(
var_one, var_two,
var_three, var_four)
这与示例的情况不同,因为在第一行中有参数。PEP8声明您应该保持函数参数垂直对齐,所以Flake8在这里是正确的。如果这样做会违反PEP8的其他规则,不要担心“保持4空间的纯度”。
如果您真的不喜欢使用非倍数4的空格,则可以切换到下列样式之一:
# More indentation included to distinguish this from the rest.
def long_function_name(
var_one, var_two, var_three,
var_four):
print(var_one)
# Hanging indents should add a level.
foo = long_function_name(
var_one, var_two,
var_three, var_four)
https://stackoverflow.com/questions/52874205
复制相似问题