Skip to content

Commit

Permalink
Do not omit any tokens when selecting the last two leaves
Browse files Browse the repository at this point in the history
  • Loading branch information
jayaddison committed Feb 3, 2021
1 parent 0bb718c commit 82ab09d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
9 changes: 3 additions & 6 deletions src/black/__init__.py
Expand Up @@ -6608,7 +6608,7 @@ def can_omit_invisible_parens(
last = line.leaves[-1]
if line.should_explode:
try:
penultimate, last = last_two_except(line.leaves, omit=omit_on_explode)
penultimate, last = last_two_except(line.leaves)
except LookupError:
# Turns out we'd omit everything. We cannot skip the optional parentheses.
return False
Expand Down Expand Up @@ -6685,7 +6685,7 @@ def _can_omit_closing_paren(line: Line, *, last: Leaf, line_length: int) -> bool
return False


def last_two_except(leaves: List[Leaf], omit: Collection[LeafID]) -> Tuple[Leaf, Leaf]:
def last_two_except(leaves: List[Leaf]) -> Tuple[Leaf, Leaf]:
"""Return (penultimate, last) leaves skipping brackets in `omit` and contents."""
stop_after = None
last = None
Expand All @@ -6698,10 +6698,7 @@ def last_two_except(leaves: List[Leaf], omit: Collection[LeafID]) -> Tuple[Leaf,
if last:
return leaf, last

if id(leaf) in omit:
stop_after = leaf.opening_bracket
else:
last = leaf
last = leaf
else:
raise LookupError("Last two leaves were also skipped")

Expand Down
2 changes: 0 additions & 2 deletions tests/test_black.py
Expand Up @@ -239,14 +239,12 @@ def test_invisible_parens_instability(self) -> None:
actual = fs(source)
black.assert_stable(source, actual, DEFAULT_MODE)

@unittest.expectedFailure
@patch("black.dump_to_file", dump_to_stderr)
def test_trailing_comma_optional_parens_stability1(self) -> None:
source, _expected = read_data("trailing_comma_optional_parens1")
actual = fs(source)
black.assert_stable(source, actual, DEFAULT_MODE)

@unittest.expectedFailure
@patch("black.dump_to_file", dump_to_stderr)
def test_trailing_comma_optional_parens_stability2(self) -> None:
source, _expected = read_data("trailing_comma_optional_parens2")
Expand Down

0 comments on commit 82ab09d

Please sign in to comment.