Skip to content

Commit 2e476f0

Browse files
bbugyi200noxan
authored andcommitted
Fix unstable subscript assignment string wrapping (psf#1678)
Fixes psf#1598
1 parent 4aa6118 commit 2e476f0

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/black/__init__.py

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

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

35143517
if is_valid_index(string_idx + 1):
35153518
N = LL[string_idx + 1]

tests/data/long_strings__regression.py

+9
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,10 @@ def xxxxxxx_xxxxxx(xxxx):
349349
x.xxxxx.xxxxxx.xxxxx.xxxx,
350350
], ("xxxxxxxxxxx xxxxxxx xxxx (xxxxxx xxxx) %x xxx xxxxx" % xxxxxxx_xxxx)
351351

352+
value.__dict__[
353+
key
354+
] = "test" # set some Thrift field to non-None in the struct aa bb cc dd ee
355+
352356
# output
353357

354358

@@ -784,3 +788,8 @@ def xxxxxxx_xxxxxx(xxxx):
784788
], (
785789
"xxxxxxxxxxx xxxxxxx xxxx (xxxxxx xxxx) %x xxx xxxxx" % xxxxxxx_xxxx
786790
)
791+
792+
793+
value.__dict__[
794+
key
795+
] = "test" # set some Thrift field to non-None in the struct aa bb cc dd ee

0 commit comments

Comments
 (0)