Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Visual Studio Code - PEP8 Lambda Issue
PEP8 is automatically formatting a part of my code, I was just learning about lambdas and I had a 2 line code like this:

My simple code: (2 lines)

What PEP 8 does: (4 lines)

it may not seem like a lot, but it went from 2 lines to 4 lines, with the huge possibility of it being a 6 line code (if I had anything above the def function, it would add another 2 lines between them.)

If the def had anything above: (6 lines)

So it can easily go from 2 lines to 6 lines!

How do I disable this function specifically for lambdas?
It's not PEP8 that format your code, but the linter extension you have installed (there are several, so it's not clear which one you use - probably the one with same name?). The purpose of linter is to make your code conform with PEP8 recommendations. How strict it will be depends on your particular settings - this is to answer the question how you can disable.
Now, in this particular case PEP8 has clear recommendation:
Quote:Always use a def statement instead of an assignment statement that binds a lambda expression directly to an identifier.


def f(x): return 2*x


f = lambda x: 2*x

The first form means that the name of the resulting function object is specifically 'f' instead of the generic '<lambda>'. This is more useful for tracebacks and string representations in general. The use of the assignment statement eliminates the sole benefit a lambda expression can offer over an explicit def statement (i.e. that it can be embedded inside a larger expression)

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Issue with code for auto checkout nqk28703 2 161 Nov-01-2019, 09:33 AM
Last Post: nqk28703
  Variable comments on Visual Studio Code sal 2 167 Oct-19-2019, 02:13 PM
Last Post: sal
  Visual Studio Python 2.2 Source Project bobosamma 5 227 Oct-14-2019, 11:19 AM
Last Post: snippsat
  In Visual Studio Python is not properly installed jalea148 4 250 Sep-26-2019, 12:31 PM
Last Post: snippsat
  run into issues while configuring visual-studio code on a win 7 machine. apollo 3 319 Sep-12-2019, 12:25 AM
Last Post: snippsat
  Visual Studio Code does not print desired output but only prints "..." vincentolivers 11 435 Sep-09-2019, 12:58 PM
Last Post: vincentolivers
  lambda layer size issue lambdabeginer 1 190 Aug-26-2019, 07:23 PM
Last Post: Larz60+
  Wrong output in Visual Studio Code py_learner 1 249 Jun-24-2019, 10:02 PM
Last Post: Yoriz
  Newb question: Debugging + Linting Python in Visual Studio Code Drone4four 1 319 Apr-15-2019, 06:19 AM
Last Post: perfringo
  code issue sandy 1 260 Mar-14-2019, 07:16 PM
Last Post: micseydel

Forum Jump:

Users browsing this thread: 1 Guest(s)