Skip to content

Commit

Permalink
don't strip brackets before lsqb (psf#1575)
Browse files Browse the repository at this point in the history
it's not safe to remove brackets that are followed by a `[`
  • Loading branch information
davidszotten committed Aug 12, 2020
1 parent bf639cc commit 56105db
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/black/__init__.py
Expand Up @@ -3287,14 +3287,11 @@ def do_match(self, line: Line) -> TMatchResult:
and LL[next_idx].type == token.RPAR
and not is_empty_rpar(LL[next_idx])
):
# That RPAR should NOT be followed by...
if is_valid_index(next_idx + 1) and (
# a '.' symbol
LL[next_idx + 1].type == token.DOT
or
# a '[' symbol
LL[next_idx + 1].type == token.LSQB
):
# That RPAR should NOT be followed by a '.' or a '['
if is_valid_index(next_idx + 1) and LL[next_idx + 1].type in {
token.DOT,
token.LSQB,
}:
continue

return Ok(string_idx)
Expand Down
3 changes: 3 additions & 0 deletions tests/data/bracketed_slicing.py
@@ -0,0 +1,3 @@
("" % a)[0]
# output
("" % a)[0]

0 comments on commit 56105db

Please sign in to comment.