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
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.
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
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 autopep8 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