mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 05:44:56 +00: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:
parent
7b4103bcb6
commit
4739bc8d14
3 changed files with 35 additions and 19 deletions
|
@ -253,7 +253,6 @@ does["not"]["exist"] = 0
|
|||
reveal_type(does["not"]["exist"]) # revealed: Unknown
|
||||
|
||||
non_subscriptable = 1
|
||||
# error: [non-subscriptable]
|
||||
non_subscriptable[0] = 0
|
||||
# error: [non-subscriptable]
|
||||
reveal_type(non_subscriptable[0]) # revealed: Unknown
|
||||
|
|
|
@ -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
|
||||
```
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue