mirror of
https://github.com/astral-sh/ruff
synced 2026-01-05 21:54:16 -05:00
[ty] Fix incorrect diagnostic when calling __setitem__ (#19645)
## Summary Resolves https://github.com/astral-sh/ty/issues/862 by not emitting a diagnostic. ## Test Plan Add test to show we don't emit the diagnostic
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# Instance subscript
|
||||
|
||||
## Getitem unbound
|
||||
## `__getitem__` unbound
|
||||
|
||||
```py
|
||||
class NotSubscriptable: ...
|
||||
@@ -8,7 +8,7 @@ class NotSubscriptable: ...
|
||||
a = NotSubscriptable()[0] # error: "Cannot subscript object of type `NotSubscriptable` with no `__getitem__` method"
|
||||
```
|
||||
|
||||
## Getitem not callable
|
||||
## `__getitem__` not callable
|
||||
|
||||
```py
|
||||
class NotSubscriptable:
|
||||
@@ -18,7 +18,7 @@ class NotSubscriptable:
|
||||
a = NotSubscriptable()[0]
|
||||
```
|
||||
|
||||
## Valid getitem
|
||||
## Valid `__getitem__`
|
||||
|
||||
```py
|
||||
class Identity:
|
||||
@@ -28,7 +28,7 @@ class Identity:
|
||||
reveal_type(Identity()[0]) # revealed: int
|
||||
```
|
||||
|
||||
## Getitem union
|
||||
## `__getitem__` union
|
||||
|
||||
```py
|
||||
def _(flag: bool):
|
||||
@@ -42,3 +42,14 @@ def _(flag: bool):
|
||||
|
||||
reveal_type(Identity()[0]) # revealed: int | str
|
||||
```
|
||||
|
||||
## `__setitem__` with no `__getitem__`
|
||||
|
||||
```py
|
||||
class NoGetitem:
|
||||
def __setitem__(self, index: int, value: int) -> None:
|
||||
pass
|
||||
|
||||
a = NoGetitem()
|
||||
a[0] = 0
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user