Fix subscript comment placement with parenthesized value (#10496)

## Summary

This is a follow up on https://github.com/astral-sh/ruff/pull/10492 

I incorrectly assumed that `subscript.value.end()` always points past
the value. However, this isn't the case for parenthesized values where
the end "ends" before the parentheses.

## Test Plan

I added new tests for the parenthesized case.
This commit is contained in:
Micha Reiser 2024-03-20 21:30:22 +01:00 committed by GitHub
parent fd3d272026
commit 9d705a4414
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 42 additions and 13 deletions

View file

@ -4,7 +4,6 @@ result = (
+ 1
)[0]
# Regression tests for: https://github.com/astral-sh/ruff/issues/10355
repro(
"some long string that takes up some space"
@ -14,7 +13,7 @@ repro(
repro(
"some long string that takes up some space"
)[0 # some long comment also taking up space
)[0 # some long comment also taking up space
]
repro(
@ -23,9 +22,20 @@ repro(
repro("some long string that takes up some space")[0] # some long comment also taking up space
repro(
"some long string that takes up some space"
)[ # some long comment also taking up space
0:-1
]
(
repro
)[ # some long comment also taking up space
0
]
(
repro # some long comment also taking up space
)[
0
]