5
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
Jakkalsie
  • 53
  • 3
  • PEP8 [States to](https://www.python.org/dev/peps/pep-0008/#blank-lines) `Surround top-level function and class definitions with two blank lines`. Since your statements are top-level, they get corrected to match that design recommendation. – b_c Jan 03 '20 at 16:22

3 Answers3

4

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

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

DeepSpace
  • 78,697
  • 11
  • 109
  • 154
4

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

  • while the link to GitHub is OK, it would be useful to include relevant aspects (as a quotation) in your answer – Andrew Oct 23 '21 at 09:59
0

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

python.formatting.autopep8Args

MutantMahesh
  • 1,480
  • 15
  • 20
  • Configure it how? I added `--ignore=E302` but it doesn't prevent it spacing everything in double lines when saving. – Hasen Apr 11 '23 at 09:14
  • @Hasen Not sure why it is not working for you but you can check https://github.com/hhatto/autopep8 for more information. – MutantMahesh Apr 12 '23 at 10:10