Skip to content
Advertisement

Auto-PEP8 is adding lines by turning my lambda into def function, how do I disable this specific auto format?

I am using Visual Studio Code and PEP8 is automatically formatting a part of my code, I was just learning about lambdas and I had a 3 line code like this:

It went from this 3 line code:

# Lambda example
divide = lambda x, y: x/y
print(divide(10, 2))

To this 7 line code:

# Lambda example


def divide(x, y): return x/y


print(divide(10, 2))

Does anyone know how do I make this program to specifically not convert my lambda function into def function?

It has been formatting my code really good, so I don’t want to completely disable this automatic feature, just for the lambda thing.

Advertisement

Answer

This is triggered by the pycodestyle code E731

You can disable this with --ignore=E731

In a config file (for instance tox.ini / setup.cfg):

[pep8] 
ignore=E731
Advertisement