-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[red-knot] Infer subscript expression types for bytes literals #13901
Changes from 6 commits
d0c406d
4455cc9
e529344
543d0ad
cc9356a
93db3dd
1c2bb9f
d29004e
24f778d
9f3b5c1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Bytes literals | ||
|
||
## Simple | ||
|
||
```py | ||
reveal_type(b"red" b"knot") # revealed: Literal[b"redknot"] | ||
reveal_type(b"hello") # revealed: Literal[b"hello"] | ||
reveal_type(b"world" + b"!") # revealed: Literal[b"world!"] | ||
reveal_type(b"\xff\x00") # revealed: Literal[b"\xff\x00"] | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,9 @@ reveal_type(s[1]) # revealed: Literal["b"] | |
reveal_type(s[-1]) # revealed: Literal["e"] | ||
reveal_type(s[-2]) # revealed: Literal["d"] | ||
|
||
reveal_type(s[False]) # revealed: Literal["a"] | ||
reveal_type(s[True]) # revealed: Literal["b"] | ||
|
||
a = s[8] # error: [index-out-of-bounds] "Index 8 is out of bounds for string `Literal["abcde"]` with length 5" | ||
reveal_type(a) # revealed: Unknown | ||
|
||
|
@@ -20,11 +23,10 @@ reveal_type(b) # revealed: Unknown | |
## Function return | ||
|
||
```py | ||
def add(x: int, y: int) -> int: | ||
return x + y | ||
Comment on lines
-23
to
-24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am assuming |
||
def int_instance() -> int: ... | ||
|
||
|
||
a = "abcde"[add(0, 1)] | ||
a = "abcde"[int_instance()] | ||
# TODO: Support overloads... Should be `str` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand that we want to infer There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We attempt to infer the type here by looking up In fact, we just infer There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! |
||
reveal_type(a) # revealed: @Todo | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These were placed in the wrong file => moved to
mdtest/literal/bytes.md
.