简体   繁体   中英

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

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM