fix: Stop moving multiline strings to a new line unless inside brackets (#4289)
Signed-off-by: RedGuy12 <61329810+RedGuy12@users.noreply.github.com>
This commit is contained in:
parent
c9d2635b55
commit
13bd0925eb
@ -16,6 +16,7 @@
|
||||
|
||||
- `if` guards in `case` blocks are now wrapped in parentheses when the line is too long.
|
||||
(#4269)
|
||||
- Stop moving multiline strings to a new line unless inside brackets (#4289)
|
||||
|
||||
### Configuration
|
||||
|
||||
|
@ -858,11 +858,13 @@ def is_line_short_enough( # noqa: C901
|
||||
return False
|
||||
|
||||
if leaf.bracket_depth <= max_level_to_update and leaf.type == token.COMMA:
|
||||
# Ignore non-nested trailing comma
|
||||
# Inside brackets, ignore trailing comma
|
||||
# directly after MLS/MLS-containing expression
|
||||
ignore_ctxs: List[Optional[LN]] = [None]
|
||||
ignore_ctxs += multiline_string_contexts
|
||||
if not (leaf.prev_sibling in ignore_ctxs and i == len(line.leaves) - 1):
|
||||
if (line.inside_brackets or leaf.bracket_depth > 0) and (
|
||||
i != len(line.leaves) - 1 or leaf.prev_sibling not in ignore_ctxs
|
||||
):
|
||||
commas[leaf.bracket_depth] += 1
|
||||
if max_level_to_update != math.inf:
|
||||
max_level_to_update = min(max_level_to_update, leaf.bracket_depth)
|
||||
|
@ -175,6 +175,13 @@ def dastardly_default_value(
|
||||
"c"
|
||||
)
|
||||
|
||||
assert some_var == expected_result, """
|
||||
test
|
||||
"""
|
||||
assert some_var == expected_result, f"""
|
||||
expected: {expected_result}
|
||||
actual: {some_var}"""
|
||||
|
||||
# output
|
||||
"""cow
|
||||
say""",
|
||||
@ -385,3 +392,10 @@ def dastardly_default_value(
|
||||
)
|
||||
|
||||
this_will_also_become_one_line = "abc" # comment
|
||||
|
||||
assert some_var == expected_result, """
|
||||
test
|
||||
"""
|
||||
assert some_var == expected_result, f"""
|
||||
expected: {expected_result}
|
||||
actual: {some_var}"""
|
||||
|
Loading…
Reference in New Issue
Block a user