gpt4 book ai didi

python - 如何让 pylint 和 autopep8 就如何缩进包装的函数定义达成一致?

转载 作者:行者123 更新时间:2023-12-03 17:26:05 27 4
gpt4 key购买 nike

如何制作美化剂 autopep8和短绒 pylint同意如何缩进我的代码,而不完全禁用缩进格式/linting? 我不介意是第一种格式还是第二种格式,只要我能点击 Alt+F在 VSCode 中并信任输出。
美化者希望代码像这样缩进......

# autopep8 prettifier
def sum(
a: int,
b: int
) -> int:
"""Return the sum of a and b."""
return a + b
...但 linter 想要这样。
# pylint linter
def sum(
a: int,
b: int
) -> int:
"""Return the sum of a and b."""
return a + b
PEP8 标准将此列为格式化函数的一种方式,但他们没有提到当右括号放在单独的行上时如何缩进。我真的更喜欢有额外的换行符,因为这将输出格式放在自己的行上,它减少了将空行作为函数体中第一行的冲动。我稍微喜欢上面的第一个选项,因为这个选项将右括号与必须打开一个的行对齐。当使用类型提示时,Google 的 Python 风格指南推荐第一个缩进示例。
# PEP8 standard
def sum(
a: int,
b: int) -> int:
"""Return the sum of a and b."""
return a + b
(对于上面的示例,最好将函数声明简单地放在一行中,但是如果不使行太长,这并不总是可行的。)

最佳答案

您可以升级到最新的pylint。 bad-continuationbad-whitespace在版本 2.6.0 中从 pylint 中删除. The pylint team thinks that black or autopep8 can help you with formatting better than Pylint.
更一般地说,我认为如果您使用的是自动格式化程序,那么您可以禁用 pylint 有关格式化的消息。

关于python - 如何让 pylint 和 autopep8 就如何缩进包装的函数定义达成一致?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53352620/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com