Describe the bug
Based on the discussion in this issue, Black has no opinion on whether a blank line should or should not exist after a docstring. Both are permitted. However, Black will add an empty new line after a docstring when using --line-ranges when the lines are within the lines containing the docstring.
To Reproduce
For example, take this code in "example.py":
def function():
"""This is a docstring."""
return "Hi There!"
And run it with these arguments:
$ black --line-ranges 2-2 example.py
"example.py" is changed to:
def function():
"""This is a docstring."""
return "Hi There!"
Expected behavior
I expect no change to the original file.
Environment
- Black's version: black, 26.5.2.dev73+gc7801d9e2
- OS and Python version: MacOS/Python 3.14.6
Additional context
This unexpected behavior was introduced in version 26.1.0 (and earlier in preview mode, but I didn't check when that occured).
I notice this error because the VS Code Black Formatter Extension often used the --line-ranges option. I notice it a lot when pasting text into a docstring because I have configured VS Code to format-on-paste.
Describe the bug
Based on the discussion in this issue, Black has no opinion on whether a blank line should or should not exist after a docstring. Both are permitted. However, Black will add an empty new line after a docstring when using
--line-rangeswhen the lines are within the lines containing the docstring.To Reproduce
For example, take this code in "example.py":
And run it with these arguments:
"example.py" is changed to:
Expected behavior
I expect no change to the original file.
Environment
Additional context
This unexpected behavior was introduced in version 26.1.0 (and earlier in preview mode, but I didn't check when that occured).
I notice this error because the VS Code Black Formatter Extension often used the
--line-rangesoption. I notice it a lot when pasting text into a docstring because I have configured VS Code to format-on-paste.