mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-09 10:00:25 +00:00
Fix find_only_token_in_range with expression parentheses (#5645)
## Summary Fix an oversight in `find_only_token_in_range` where the following code would panic due do the closing and opening parentheses being in the range we scan: ```python d1 = [ ("a") if # 1 ("b") else # 2 ("c") ] ``` Closing and opening parentheses respectively are now correctly skipped. ## Test Plan I added a regression test
This commit is contained in:
parent
82317ba1fd
commit
cab3a507bc
3 changed files with 32 additions and 2 deletions
|
@ -37,6 +37,14 @@ c2 = (
|
|||
# 8
|
||||
"b" # 9
|
||||
)
|
||||
|
||||
# regression test: parentheses outside the expression ranges interfering with finding
|
||||
# the `if` and `else` token finding
|
||||
d1 = [
|
||||
("a") if # 1
|
||||
("b") else # 2
|
||||
("c")
|
||||
]
|
||||
```
|
||||
|
||||
## Output
|
||||
|
@ -78,6 +86,16 @@ c2 = (
|
|||
# 8
|
||||
else "b" # 9
|
||||
)
|
||||
|
||||
# regression test: parentheses outside the expression ranges interfering with finding
|
||||
# the `if` and `else` token finding
|
||||
d1 = [
|
||||
("a")
|
||||
# 1
|
||||
if ("b")
|
||||
# 2
|
||||
else ("c")
|
||||
]
|
||||
```
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue