Pep8 Visual Studio Code



Jan-28-2019, 05:20 AM (This post was last modified: Jan-28-2019, 05:20 AM by Qui_Ten.)
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?
Jan-28-2019, 08:17 AM (This post was last modified: Jan-28-2019, 08:17 AM by buran.)
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)
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs
  1. Vscode Python Pep8
  2. Vscode Autopep8 Args
  3. Pylint Pep8
  4. Vscode Pep8 Check
  5. Vscode Pep8 Linter

Set PyLint command-line options. The command-line options section of the PyLint documentation describes how to control PyLint's behavior through a.pylintrc configuration file. Such a file can be placed in the root of a Python project in Visual Studio or elsewhere depending on how widely you want those settings applied (see the command-line options for details). Installing and Configuring Visual Studio Code for Python Development. Installing Visual Studio Code is very accessible on any platform. Full instructions for Windows, Mac, and Linux are available, and the editor is updated monthly with new features and bug fixes. You can find everything at the Visual Studio Code website. In case you were wondering, Visual Studio Code (or VS Code for short.

Code
Possibly Related Threads…
ThreadAuthorRepliesViewsLast Post
Noob warning: trying to use pip to install pytest and pep8 in Command Promptadifrank4465Dec-20-2020, 04:23 AM
Last Post: adifrank
Visual Studio Code helpaaronrousch2696Aug-04-2020, 10:34 AM
Last Post: snippsat
Problems on 'no such file or directory' in python on Visual studio 201950441643011,071Aug-02-2020, 08:38 PM
Last Post: Larz60+
Visual Studio-remove Output cluttermds142,200Jun-04-2020, 11:47 PM
Last Post: mds
Type hinting style and PEP8hlovatt2693May-07-2020, 08:12 PM
Last Post: hlovatt
Issue with code for auto checkoutnqk287032785Nov-01-2019, 09:33 AM
Last Post: nqk28703
Variable comments on Visual Studio Codesal2878Oct-19-2019, 02:13 PM
Last Post: sal
Visual Studio Python 2.2 Source Projectbobosamma5941Oct-14-2019, 11:19 AM
Last Post: snippsat
In Visual Studio Python is not properly installedjalea1484992Sep-26-2019, 12:31 PM
Last Post: snippsat
run into issues while configuring visual-studio code on a win 7 machine.apollo31,367Sep-12-2019, 12:25 AM
Last Post: snippsat
Users browsing this thread: 1 Guest(s)

Vscode Python Pep8


Vscode Autopep8 Args

Default Formatter

Code formatting is supported using either one of yapf or autopep8.
The default code format provider is autopep8.

Auto Formatting

Formatting the source code as and when you save the contents of the file is supported.
Enabling this requires configuring the setting 'editor.formatOnSave': true as identified here.

Paths

All samples provided here are for windows.
However Mac/Linux paths are also supported.

AutoPep8

You can configure the format provider by changing a setting in the User or Workspace settings file as follows:

Installing autopep8

Custom Path

This is generally unnecessary. As the Extension will resolve the path to the formatter based on Python executable being used or configured in python.pythonPath of settings.json. If this cannot be found, then the formatter will be resolved based on the current environment Path settings.

If this is not the case or you wish to use another version of autopep8, all you need to do is configure the path as follows either in the User or Workspace settings file:

Studio

Yapf

You can configure the format provider by changing a setting in the User or Workspace settings file as follows:

Custom Path

This is generally unnecessary. As the Extension will resolve the path to the formatter based on Python executable being used or configured in python.pythonPath of settings.json. If this cannot be found, then the formatter will be resolved based on the current environment Path settings.

Pylint Pep8

If this is not the case or you wish to use another version of yapf, all you need to do is configure the path as follows either in the User or Workspace settings file:

Vscode Pep8 Check

Custom arguments to Yapf

Vscode Pep8 Linter

Custom arguments can be passed into yaps by configuring the settings in the User or Workspace settings as follows:

Installing Yapf

pip install yapf