PyCharm PEP8 类型参数违规

PyCharm PEP8 Violation for typed parameters

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')

有没有人找到一种方法让 PyCharm 的自动格式化程序在输入时发现间距违规?

您对 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): ...