Skip to content

Commit

Permalink
Fix an infinite recursion error exposed by #3440 (#3444)
Browse files Browse the repository at this point in the history
  • Loading branch information
yilei committed Dec 16, 2022
1 parent aafc21a commit 7816393
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/black/linegen.py
Expand Up @@ -1417,8 +1417,10 @@ def run_transformer(

result.extend(transform_line(transformed_line, mode=mode, features=features))

features_set = set(features)
if (
transform.__class__.__name__ != "rhs"
Feature.FORCE_OPTIONAL_PARENTHESES in features_set
or transform.__class__.__name__ != "rhs"
or not line.bracket_tracker.invisible
or any(bracket.value for bracket in line.bracket_tracker.invisible)
or line.contains_multiline_strings()
Expand All @@ -1435,7 +1437,7 @@ def run_transformer(

line_copy = line.clone()
append_leaves(line_copy, line, line.leaves)
features_fop = set(features) | {Feature.FORCE_OPTIONAL_PARENTHESES}
features_fop = features_set | {Feature.FORCE_OPTIONAL_PARENTHESES}
second_opinion = run_transformer(
line_copy, transform, mode, features_fop, line_str=line_str
)
Expand Down
37 changes: 37 additions & 0 deletions tests/data/preview/long_dict_values.py
Expand Up @@ -17,6 +17,24 @@
"a key in my dict": MyClass.some_attribute.first_call().second_call().third_call(some_args="some value")
}

{
'xxxxxx':
xxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxx(
xxxxxxxxxxxxxx={
'x':
xxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxx(
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=(
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx(
xxxxxxxxxxxxx=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx(
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx={
'x': x.xx,
'x': x.x,
}))))
}),
}


# output

Expand Down Expand Up @@ -51,3 +69,22 @@
.third_call(some_args="some value")
)
}

{
"xxxxxx": xxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxx(
xxxxxxxxxxxxxx={
"x": xxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxx(
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=(
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx(
xxxxxxxxxxxxx=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx(
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx={
"x": x.xx,
"x": x.x,
}
)
)
)
)
}
),
}

0 comments on commit 7816393

Please sign in to comment.