gpt4 book ai didi

python - PyCharm PEP8 类型参数违规

转载 作者:太空宇宙 更新时间:2023-11-03 14:00:53 25 4
gpt4 key购买 nike

PEP8 建议函数参数中相等运算符周围不要有空格。

例如:

正确:

def func(a=0):
print('PEP8 compliant spacing')

不正确:

def func(a = 0):
print('Invalid PEP8 spacing')

typing 时,PyCharm 的自动格式化程序无法拾取不正确的间距已经包括了。

例如,PyCharm 不会正确格式化以下函数:

def func(a: int = 0):
print('Invalid PEP8 spacing')

收件人:

def func(a: int=0):
print('PEP8 compliant spacing')

有没有人找到一种方法让 PyC​​harm 的自动格式化程序在存在打字的地方发现间距违规?

最佳答案

您对 PEP8 的引用有误.在这种情况下,空格应该在那里:

When combining an argument annotation with a default value, use spaces around the = sign (but only for those arguments that have both an annotation and a default).

Yes:

def munge(sep: AnyStr = None): ...

No:

def munge(input: AnyStr=None): ...
def munge(input: AnyStr, limit = 1000): ...

关于python - PyCharm PEP8 类型参数违规,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49255742/

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