Fix an issue where extra empty lines are added. (#3470)
This commit is contained in:
parent
59f03d1b9d
commit
29dd257253
@ -23,6 +23,8 @@
|
|||||||
regular and f-strings start with an empty span (#3463)
|
regular and f-strings start with an empty span (#3463)
|
||||||
- Fix a crash in preview advanced string processing where a standalone comment is placed
|
- Fix a crash in preview advanced string processing where a standalone comment is placed
|
||||||
before a dict's value (#3469)
|
before a dict's value (#3469)
|
||||||
|
- Fix an issue where extra empty lines are added when a decorator has `# fmt: skip`
|
||||||
|
applied or there is a standalone comment between decorators (#3470)
|
||||||
- Do not put the closing quotes in a docstring on a separate line, even if the line is
|
- Do not put the closing quotes in a docstring on a separate line, even if the line is
|
||||||
too long (#3430)
|
too long (#3430)
|
||||||
- Long values in dict literals are now wrapped in parentheses; correspondingly
|
- Long values in dict literals are now wrapped in parentheses; correspondingly
|
||||||
|
@ -520,7 +520,8 @@ def maybe_empty_lines(self, current_line: Line) -> LinesBlock:
|
|||||||
and (self.semantic_leading_comment is None or before)
|
and (self.semantic_leading_comment is None or before)
|
||||||
):
|
):
|
||||||
self.semantic_leading_comment = block
|
self.semantic_leading_comment = block
|
||||||
elif not current_line.is_decorator:
|
# `or before` means this decorator already has an empty line before
|
||||||
|
elif not current_line.is_decorator or before:
|
||||||
self.semantic_leading_comment = None
|
self.semantic_leading_comment = None
|
||||||
|
|
||||||
self.previous_line = current_line
|
self.previous_line = current_line
|
||||||
|
@ -114,6 +114,31 @@ def first_method(self):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
# Regression test for https://github.com/psf/black/issues/3454.
|
||||||
|
def foo():
|
||||||
|
pass
|
||||||
|
# Trailing comment that belongs to this function
|
||||||
|
|
||||||
|
|
||||||
|
@decorator1
|
||||||
|
@decorator2 # fmt: skip
|
||||||
|
def bar():
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
# Regression test for https://github.com/psf/black/issues/3454.
|
||||||
|
def foo():
|
||||||
|
pass
|
||||||
|
# Trailing comment that belongs to this function.
|
||||||
|
# NOTE this comment only has one empty line below, and the formatter
|
||||||
|
# should enforce two blank lines.
|
||||||
|
|
||||||
|
@decorator1
|
||||||
|
# A standalone comment
|
||||||
|
def bar():
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
# output
|
# output
|
||||||
|
|
||||||
|
|
||||||
@ -252,3 +277,29 @@ class MyClass:
|
|||||||
# More comments.
|
# More comments.
|
||||||
def first_method(self):
|
def first_method(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
# Regression test for https://github.com/psf/black/issues/3454.
|
||||||
|
def foo():
|
||||||
|
pass
|
||||||
|
# Trailing comment that belongs to this function
|
||||||
|
|
||||||
|
|
||||||
|
@decorator1
|
||||||
|
@decorator2 # fmt: skip
|
||||||
|
def bar():
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
# Regression test for https://github.com/psf/black/issues/3454.
|
||||||
|
def foo():
|
||||||
|
pass
|
||||||
|
# Trailing comment that belongs to this function.
|
||||||
|
# NOTE this comment only has one empty line below, and the formatter
|
||||||
|
# should enforce two blank lines.
|
||||||
|
|
||||||
|
|
||||||
|
@decorator1
|
||||||
|
# A standalone comment
|
||||||
|
def bar():
|
||||||
|
pass
|
||||||
|
Loading…
Reference in New Issue
Block a user