首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >用于对齐延长线的额外空间

用于对齐延长线的额外空间
EN

Stack Overflow用户
提问于 2018-10-18 12:36:36
回答 1查看 958关注 0票数 0

我已经开始使用Flake8检查我的python代码,但是它总是给我一个错误/警告--我觉得排序很痛苦--是“缩进/缩进的继续行”。

Flake8希望我的延拓行与起始括号完全对齐。因此,在下面的示例中,Flake8不喜欢前两个,但喜欢第三个:(?)=4个空格,·=单个空格)

代码语言:javascript
运行
复制
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空间的纯度。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-10-18 12:49:06

引用相关PEP8页面的脚注:

悬挂式缩进是一种类型设置样式,除第一行外,段落中的所有行都是缩进的。在Python上下文中,该术语用于描述一种样式,其中括号大小语句的开始括号是该行的最后一个非空格字符,随后的行被缩进,直到结束括号。

代码语言:javascript
运行
复制
# 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的空格,则可以切换到下列样式之一:

代码语言:javascript
运行
复制
# 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)
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52874205

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档