Skip to content

Commit

Permalink
Do not treat "... # comment" as a dummy implementation
Browse files Browse the repository at this point in the history
Fixes psf#4063
  • Loading branch information
JelleZijlstra committed Nov 21, 2023
1 parent be336bb commit eece597
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions src/black/nodes.py
Expand Up @@ -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()
Expand Down
7 changes: 7 additions & 0 deletions tests/data/cases/preview_dummy_implementations.py
Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit eece597

Please sign in to comment.