Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Visual Studio Code - PEP8 Lambda Issue
#1
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?
Quote
#2
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.

Yes:

def f(x): return 2*x

No:

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)
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Question about using lambda hikerguy62 3 116 Today, 07:18 AM
Last Post: perfringo
  Using map and lambda in a matrix ricardodepaula 3 120 Jul-21-2019, 03:42 PM
Last Post: ricardodepaula
  Lambda function Uchikago 3 167 Jul-16-2019, 08:56 AM
Last Post: perfringo
  Wrong output in Visual Studio Code py_learner 1 137 Jun-24-2019, 10:02 PM
Last Post: Yoriz
  Newb question: Debugging + Linting Python in Visual Studio Code Drone4four 1 187 Apr-15-2019, 06:19 AM
Last Post: perfringo
  code issue sandy 1 181 Mar-14-2019, 07:16 PM
Last Post: micseydel
  eval lambda function with restricted context Olivier 7 393 Mar-04-2019, 10:45 PM
Last Post: Olivier
  AWS lambda script help - Listing untagged volumes jutler 0 293 Feb-13-2019, 02:36 PM
Last Post: jutler
  How to set up visual studio 2017 for 3ds max Python development littleGreenDude 1 444 Dec-27-2018, 04:51 PM
Last Post: littleGreenDude
  Wine / liquor dispenser project code issue onlinegill 0 346 Nov-20-2018, 10:41 PM
Last Post: onlinegill

Forum Jump:


Users browsing this thread: 1 Guest(s)