-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[ty] Type-context aware literal promotion #20776
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
Changes from all commits
8a172d7
06696c7
e12d0bd
3260b03
41af679
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 |
---|---|---|
|
@@ -525,10 +525,6 @@ from typing import Literal | |
reveal_type(list((1, 2, 3))) # revealed: list[int] | ||
reveal_type(list(((1, 2, 3),))) # revealed: list[tuple[int, int, int]] | ||
|
||
# TODO: we could bidirectionally infer that the user does not want literals to be promoted here, | ||
# and avoid this diagnostic | ||
# | ||
# error: [invalid-assignment] "`list[int]` is not assignable to `list[Literal[1, 2, 3]]`" | ||
Comment on lines
-528
to
-531
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. there are some interesting examples above this for unannotated But we need to be careful: |
||
x: list[Literal[1, 2, 3]] = list((1, 2, 3)) | ||
reveal_type(x) # revealed: list[Literal[1, 2, 3]] | ||
``` | ||
|
Uh oh!
There was an error while loading. Please reload this page.