diff --git a/CHANGES.md b/CHANGES.md index 18bab5131e6..975de8a131f 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -16,6 +16,7 @@ - Additional cases of immediately nested tuples, lists, and dictionaries are now indented less (#4012) +- Keep suites consisting of an ellipsis followed by a comment on their own lines (#4066) ### Configuration diff --git a/src/black/nodes.py b/src/black/nodes.py index de53f8e36a3..fcfd6c9bae3 100644 --- a/src/black/nodes.py +++ b/src/black/nodes.py @@ -765,6 +765,10 @@ def is_stub_body(node: LN) -> bool: if len(node.children) != 2: return False + # If there is a comment after the ..., don't treat this suite as a stub body. + if node.children[1].prefix.strip(): + return False + child = node.children[0] return ( not child.prefix.strip() diff --git a/tests/data/cases/preview_dummy_implementations.py b/tests/data/cases/preview_dummy_implementations.py index 98b69bf87b2..38087def4cf 100644 --- a/tests/data/cases/preview_dummy_implementations.py +++ b/tests/data/cases/preview_dummy_implementations.py @@ -48,6 +48,9 @@ def b(arg: Union[int, str, object]) -> Union[int, str]: raise TypeError return arg +def has_comment(): + ... # not a dummy + # output from typing import NoReturn, Protocol, Union, overload @@ -98,3 +101,7 @@ def b(arg: Union[int, str, object]) -> Union[int, str]: if not isinstance(arg, (int, str)): raise TypeError return arg + + +def has_comment(): + ... # not a dummy