Fix INTERNAL ERROR caused by removing parens from pointless string (#1888)
Fixes #1846.
This commit is contained in:
parent
a497570fcb
commit
e912c7ff54
@ -3271,7 +3271,8 @@ class StringParenStripper(StringTransformer):
|
|||||||
|
|
||||||
Requirements:
|
Requirements:
|
||||||
The line contains a string which is surrounded by parentheses and:
|
The line contains a string which is surrounded by parentheses and:
|
||||||
- The target string is NOT the only argument to a function call).
|
- The target string is NOT the only argument to a function call.
|
||||||
|
- The target string is NOT a "pointless" string.
|
||||||
- If the target string contains a PERCENT, the brackets are not
|
- If the target string contains a PERCENT, the brackets are not
|
||||||
preceeded or followed by an operator with higher precedence than
|
preceeded or followed by an operator with higher precedence than
|
||||||
PERCENT.
|
PERCENT.
|
||||||
@ -3295,6 +3296,14 @@ def do_match(self, line: Line) -> TMatchResult:
|
|||||||
if leaf.type != token.STRING:
|
if leaf.type != token.STRING:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
# If this is a "pointless" string...
|
||||||
|
if (
|
||||||
|
leaf.parent
|
||||||
|
and leaf.parent.parent
|
||||||
|
and leaf.parent.parent.type == syms.simple_stmt
|
||||||
|
):
|
||||||
|
continue
|
||||||
|
|
||||||
# Should be preceded by a non-empty LPAR...
|
# Should be preceded by a non-empty LPAR...
|
||||||
if (
|
if (
|
||||||
not is_valid_index(idx - 1)
|
not is_valid_index(idx - 1)
|
||||||
|
@ -375,6 +375,27 @@ def xxxxxxx_xxxxxx(xxxx):
|
|||||||
print(f"Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam. {[f'{i}' for i in range(10)]}")
|
print(f"Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam. {[f'{i}' for i in range(10)]}")
|
||||||
x = f"This is a long string which contains an f-expr that should not split {{{[i for i in range(5)]}}}."
|
x = f"This is a long string which contains an f-expr that should not split {{{[i for i in range(5)]}}}."
|
||||||
|
|
||||||
|
# The parens should NOT be removed in this case.
|
||||||
|
(
|
||||||
|
"my very long string that should get formatted if I'm careful to make sure it goes"
|
||||||
|
" over 88 characters which it has now"
|
||||||
|
)
|
||||||
|
|
||||||
|
# The parens should NOT be removed in this case.
|
||||||
|
(
|
||||||
|
"my very long string that should get formatted if I'm careful to make sure it goes over 88 characters which"
|
||||||
|
" it has now"
|
||||||
|
)
|
||||||
|
|
||||||
|
# The parens should NOT be removed in this case.
|
||||||
|
(
|
||||||
|
"my very long string"
|
||||||
|
" that should get formatted"
|
||||||
|
" if I'm careful to make sure"
|
||||||
|
" it goes over 88 characters which"
|
||||||
|
" it has now"
|
||||||
|
)
|
||||||
|
|
||||||
# output
|
# output
|
||||||
|
|
||||||
|
|
||||||
@ -844,3 +865,24 @@ def xxxxxxx_xxxxxx(xxxx):
|
|||||||
"This is a long string which contains an f-expr that should not split"
|
"This is a long string which contains an f-expr that should not split"
|
||||||
f" {{{[i for i in range(5)]}}}."
|
f" {{{[i for i in range(5)]}}}."
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# The parens should NOT be removed in this case.
|
||||||
|
(
|
||||||
|
"my very long string that should get formatted if I'm careful to make sure it goes"
|
||||||
|
" over 88 characters which it has now"
|
||||||
|
)
|
||||||
|
|
||||||
|
# The parens should NOT be removed in this case.
|
||||||
|
(
|
||||||
|
"my very long string that should get formatted if I'm careful to make sure it goes"
|
||||||
|
" over 88 characters which it has now"
|
||||||
|
)
|
||||||
|
|
||||||
|
# The parens should NOT be removed in this case.
|
||||||
|
(
|
||||||
|
"my very long string"
|
||||||
|
" that should get formatted"
|
||||||
|
" if I'm careful to make sure"
|
||||||
|
" it goes over 88 characters which"
|
||||||
|
" it has now"
|
||||||
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user