Skip to content

Commit

Permalink
change logic
Browse files Browse the repository at this point in the history
  • Loading branch information
hauntsaninja committed Jul 23, 2023
1 parent 5b228b1 commit 7de270e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/black/lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -725,14 +725,15 @@ def _maybe_empty_lines_for_class_or_def( # noqa: C901
else:
newlines = 0
else:
newlines = 1 if current_line.depth else 2
# If a user has left no space after a dummy implementation, don't insert
# new lines. This is useful for instance for @overload or Protocols.
if (
Preview.dummy_implementations in self.mode
and self.previous_line.is_stub_def
and (current_line.is_stub_def or current_line.is_decorator)
and not bool(user_hint_before)
):
newlines = user_hint_before
else:
newlines = 1 if current_line.depth else 2
newlines = 0
if comment_to_add_newlines is not None:
previous_block = comment_to_add_newlines.previous_block
if previous_block is not None:
Expand Down
32 changes: 30 additions & 2 deletions tests/data/preview/dummy_implementations.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@ def dummy_three():
def dummy_four():
...

@overload
def b(arg: int) -> int: ...

@overload
def b(arg: str) -> str: ...
@overload
def b(arg: object) -> NoReturn: ...

def b(arg: Union[int, str, object]) -> Union[int, str]:
if not isinstance(arg, (int, str)):
raise TypeError
return arg

# output

from typing import NoReturn, Protocol, Union, overload
Expand All @@ -49,8 +62,6 @@ def a(arg: int) -> int: ...
def a(arg: str) -> str: ...
@overload
def a(arg: object) -> NoReturn: ...


def a(arg: Union[int, str, object]) -> Union[int, str]:
if not isinstance(arg, (int, str)):
raise TypeError
Expand All @@ -68,4 +79,21 @@ def dummy_two(): ...
@dummy
def dummy_three(): ...


def dummy_four(): ...


@overload
def b(arg: int) -> int: ...


@overload
def b(arg: str) -> str: ...
@overload
def b(arg: object) -> NoReturn: ...


def b(arg: Union[int, str, object]) -> Union[int, str]:
if not isinstance(arg, (int, str)):
raise TypeError
return arg

0 comments on commit 7de270e

Please sign in to comment.