[red-knot] Minor follow-up on slice expression inference (#13982)
## Summary Minor follow-up to #13917 — thanks @AlexWaygood for the post-merge review. - Add SliceLiteralType::as_tuple - Use .expect() instead of SAFETY comment - Match on ::try_from result - Add TODO comment regarding raising a diagnostic for `"foo"["bar":"baz"]`
This commit is contained in:
@@ -86,3 +86,14 @@ substring2 = str_instance()[0:5]
|
||||
# TODO: Support overloads... Should be `str`
|
||||
reveal_type(substring2) # revealed: @Todo
|
||||
```
|
||||
|
||||
## Unsupported slice types
|
||||
|
||||
```py
|
||||
# TODO: It would be great if we raised an error here. This can be done once
|
||||
# we have support for overloads and generics, and once typeshed has a more
|
||||
# precise annotation for `str.__getitem__`, that makes use of the generic
|
||||
# `slice[..]` type. We could then infer `slice[str, str]` here and see that
|
||||
# it doesn't match the signature of `str.__getitem__`.
|
||||
"foo"["bar":"baz"]
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user