mirror of
https://github.com/astral-sh/ruff
synced 2026-01-05 21:54:16 -05:00
[ty] Improve diagnostic range for non-subscriptable diagnostics (#21461)
## Summary Currently our diagnostic only covers the range of the thing being subscripted: <img width="1702" height="312" alt="image" src="https://github.com/user-attachments/assets/7e630431-e846-46ca-93c1-139f11aaba11" /> But it should probably cover the _whole_ subscript expression (arguably the more "incorrect" bit is the `["foo"]` part of this expression, not the `x` part of this expression!) ## Test Plan Added a snapshot Co-authored-by: Brent Westbrook <36778786+ntBre@users.noreply.github.com>
This commit is contained in:
@@ -2,10 +2,12 @@
|
||||
|
||||
## `__getitem__` unbound
|
||||
|
||||
<!-- snapshot-diagnostics -->
|
||||
|
||||
```py
|
||||
class NotSubscriptable: ...
|
||||
|
||||
a = NotSubscriptable()[0] # error: "Cannot subscript object of type `NotSubscriptable` with no `__getitem__` method"
|
||||
a = NotSubscriptable()[0] # error: [non-subscriptable]
|
||||
```
|
||||
|
||||
## `__getitem__` not callable
|
||||
|
||||
Reference in New Issue
Block a user