Skip to content

Commit f1c2d55

Browse files
committed
Fix unstable subscript assignment string wrapping
Fixes #1598
1 parent 7bca930 commit f1c2d55

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/black/__init__.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -3490,9 +3490,12 @@ def __get_max_string_length(self, line: Line, string_idx: int) -> int:
34903490
# WMA4 a single space.
34913491
offset += 1
34923492

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

34973500
if is_valid_index(string_idx + 1):
34983501
N = LL[string_idx + 1]

tests/data/long_strings__regression.py

+8
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,10 @@ def who(self):
330330
% (i)
331331
)
332332

333+
value.__dict__[
334+
key
335+
] = "test" # set some Thrift field to non-None in the struct aa bb cc dd ee
336+
333337
# output
334338

335339

@@ -742,3 +746,7 @@ def who(self):
742746
r"for pid in $(ps aux | grep paster | grep -v grep | grep '\-%d' | awk"
743747
r" '{print $2}'); do kill $pid; done" % (i)
744748
)
749+
750+
value.__dict__[
751+
key
752+
] = "test" # set some Thrift field to non-None in the struct aa bb cc dd ee

0 commit comments

Comments
 (0)