support pep593 annotations#333
Merged
charliermarsh merged 7 commits intoastral-sh:mainfrom Oct 6, 2022
Merged
Conversation
adriangb
commented
Oct 6, 2022
src/check_ast.rs
Outdated
Comment on lines
+695
to
+700
| if match_name_or_attr(value, "Literal") { | ||
| self.in_literal = true; | ||
| } | ||
| if match_name_or_attr(value, "Annotated") { | ||
| self.in_pep593_annotated = true; | ||
| } |
Contributor
Author
There was a problem hiding this comment.
As a side note: it's totally valid to do from typing import Literal as Foo, I think this is just checking the name of the variable right?
Member
There was a problem hiding this comment.
Yeah that's right. These checks are a bit limited in that they don't follow reassignment for these identifiers.
Member
|
Thanks for this! Excited to review. |
Member
|
Great PR! Thanks for putting it together! I made a couple minor tweaks but nothing major. |
adriangb
commented
Oct 6, 2022
Comment on lines
+119
to
+135
| ExprKind::Attribute { attr, .. } => { | ||
| if typing::is_annotated_subscript(attr) { | ||
| Some(SubscriptKind::AnnotatedSubscript) | ||
| } else if typing::is_pep593_annotated_subscript(attr) { | ||
| Some(SubscriptKind::PEP593AnnotatedSubscript) | ||
| } else { | ||
| None | ||
| } | ||
| } | ||
| ExprKind::Name { id, .. } => { | ||
| if typing::is_annotated_subscript(id) { | ||
| Some(SubscriptKind::AnnotatedSubscript) | ||
| } else if typing::is_pep593_annotated_subscript(id) { | ||
| Some(SubscriptKind::PEP593AnnotatedSubscript) | ||
| } else { | ||
| None | ||
| } |
Contributor
Author
There was a problem hiding this comment.
This can definitely be refactored to avoid duplication, I got lazy 😴
nkxxll
pushed a commit
to nkxxll/ruff
that referenced
this pull request
Mar 10, 2024
) ## Summary I think this code has existed since the start of `typing.Annotated` support (astral-sh#333), and was then overlooked over a series of refactors. Closes astral-sh#10279.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Currently PEP593 annotations throw an error because they are being processed as regular type annotations where instead the first argument should be processed as a regular annotations and the rest should be processed as arbitrary code (and can have string constants, which is what causes the current error).