Skip to content

Commit

Permalink
Temporarily revert src directory changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jayaddison committed Feb 4, 2021
1 parent 27e1f05 commit 6c6d262
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
27 changes: 27 additions & 0 deletions src/black/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6604,6 +6604,12 @@ def can_omit_invisible_parens(

penultimate = line.leaves[-2]
last = line.leaves[-1]
if line.should_explode:
try:
penultimate, last = last_two_except(line.leaves, omit=omit_on_explode)
except LookupError:
# Turns out we'd omit everything. We cannot skip the optional parentheses.
return False

if (
last.type == token.RPAR
Expand Down Expand Up @@ -6677,6 +6683,27 @@ 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]:
"""Return (penultimate, last) leaves skipping brackets in `omit` and contents."""
stop_after = None
last = None
for leaf in reversed(leaves):
if stop_after:
if leaf is stop_after:
stop_after = None
continue

if last:
return leaf, last

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


def run_transformer(
line: Line,
transform: Transformer,
Expand Down
2 changes: 1 addition & 1 deletion src/black_primer/primer.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
},
"sqlalchemy": {
"cli_arguments": [],
"expect_formatting_changes": true,
"expect_formatting_changes": false,
"git_clone_url": "https://github.com/sqlalchemy/sqlalchemy.git",
"long_checkout": false,
"py_versions": ["all"]
Expand Down

0 comments on commit 6c6d262

Please sign in to comment.