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:
JavaScript
x
4
1
# Lambda example
2
divide = lambda x, y: x/y
3
print(divide(10, 2))
4
To this 7 line code:
JavaScript
1
8
1
# Lambda example
2
3
4
def divide(x, y): return x/y
5
6
7
print(divide(10, 2))
8
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):
JavaScript
1
3
1
[pep8]
2
ignore=E731
3