Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does VS-Code Autopep8 format 2 white lines?

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
like image 920
Jakkalsie Avatar asked Jul 21 '26 13:07

Jakkalsie


2 Answers

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

like image 129
Lucian Tarbă Avatar answered Jul 23 '26 08:07

Lucian Tarbă


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

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

like image 21
DeepSpace Avatar answered Jul 23 '26 07:07

DeepSpace