Reputation: 1480
I write code in Python in VS code. If I add comment before function and hit save button, VS code adds two empty lines:
# comment
def MyMethod():
return 0
In settings I see that I use autopep8 formatter:
I wasnt able to find what causes this annoying issue. Maybe I can configure settings somewhere?
Upvotes: 5
Views: 2845
Reputation: 297
Add --ignore=E302,E265
to python.formatting.autopep8Args
can also be an alternative way to ignore the extra two lines between the outer layer comment and code. The downside is that it would not correct the right number of lines between two functions anymore.
Upvotes: 0
Reputation: 359
Comment documenting function behavior should be placed inside function, just below signature. If it is not describing function (is placed outside function) it should have those blank lines. Don't mess with language's conventions, it's very bad idea.
Edit, Further clarification:
"""Module-level comment
"""
def function():
"""Function level comment.
There are multiple conventions explaining how
a comment's body should be formed.
"""
return 0
Upvotes: 3
Reputation:
This is due to the code convention (PEP8) of Python. Pylance will correct your code when saving.
This is an excerpt of PEP8 which you can find here:
You should use two spaces after a sentence-ending period.
If the comment describes your function, try using Docstrings.
Upvotes: 1