Skip to content

Commit

Permalink
Fix unstable subscript assignment string wrapping (#1678)
Browse files Browse the repository at this point in the history
Fixes #1598
  • Loading branch information
bbugyi200 committed Sep 10, 2020
1 parent 1e8916f commit cd055ef
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/black/__init__.py
Expand Up @@ -3507,9 +3507,12 @@ def __get_max_string_length(self, line: Line, string_idx: int) -> int:
# WMA4 a single space.
offset += 1

# WMA4 the lengths of any leaves that came before that space.
for leaf in LL[: p_idx + 1]:
# WMA4 the lengths of any leaves that came before that space,
# but after any closing bracket before that space.
for leaf in reversed(LL[: p_idx + 1]):
offset += len(str(leaf))
if leaf.type in CLOSING_BRACKETS:
break

if is_valid_index(string_idx + 1):
N = LL[string_idx + 1]
Expand Down
9 changes: 9 additions & 0 deletions tests/data/long_strings__regression.py
Expand Up @@ -349,6 +349,10 @@ def xxxxxxx_xxxxxx(xxxx):
x.xxxxx.xxxxxx.xxxxx.xxxx,
], ("xxxxxxxxxxx xxxxxxx xxxx (xxxxxx xxxx) %x xxx xxxxx" % xxxxxxx_xxxx)

value.__dict__[
key
] = "test" # set some Thrift field to non-None in the struct aa bb cc dd ee

# output


Expand Down Expand Up @@ -784,3 +788,8 @@ def xxxxxxx_xxxxxx(xxxx):
], (
"xxxxxxxxxxx xxxxxxx xxxx (xxxxxx xxxx) %x xxx xxxxx" % xxxxxxx_xxxx
)


value.__dict__[
key
] = "test" # set some Thrift field to non-None in the struct aa bb cc dd ee

0 comments on commit cd055ef

Please sign in to comment.