Why does VS-Code Autopep8 format 2 white lines?

Question:

print("Hello")

def world():
    print("Hello")

world()

Gets corrected to:

print("Hello")


def world():
    print("Hello")


world()

I have tried to:

  • Reinstall Virtual Studio Code
  • Reinstall Python 3.8
  • Computer Reboot
  • Using other formatters like Black and yapf but got the same result
Asked By: Jakkalsie

||

Answers:

Because autopep8 follows PEP8 which suggests 2 blank lines around top-level functions.

Surround top-level function and class definitions with two blank lines.

Answered By: DeepSpace

You can disable this by using the following configuration in your .vscode/settings.json

{
    "python.formatting.provider": "autopep8",
    "python.formatting.autopep8Args": [
        "--ignore=E302"
    ]
}

Here are all the autopep8 features explained: https://github.com/hhatto/autopep8#features

Answered By: Lucian Tarbă

you can also configure python.formatting.autopep8Args under your vscode setting.

python.formatting.autopep8Args

Answered By: MutantMahesh
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.