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.
There are some methods to disable auto converting lambda to function definition.
Using --ignore=E731
as explained by Anthony Sottile in (his/her) answer. Press Ctrl+,
, search for autopep8
, and add item --ignore=E731
as shown in the following screenshot.
Or you uninstall autopep8
first by invoking pip uninstall autopep8
and then install yapf
via pip install yapf
.
I let others add other methods from this line.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With