Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyCharm PEP8 Violation for typed parameters

PEP8 suggests no spaces around equal operators in function parameters.

For example:

Correct:

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

Incorrect:

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

PyCharm's auto-formatter fails to pick up incorrect spacing when typing is included.

For example, PyCharm does not correctly format the following function:

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

To:

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

Has anyone found a way to have PyCharm's auto-formatter pick up spacing violations where typing is present?

like image 355
Renier Botha Avatar asked Sep 13 '25 01:09

Renier Botha


1 Answers

You are mistaken in your quoting of PEP8. The whitespace is supposed to be there in this case:

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

like image 56
FlyingTeller Avatar answered Sep 14 '25 16:09

FlyingTeller