Understand typing.Optional in annotations#14397
Merged
AlexWaygood merged 5 commits intoastral-sh:mainfrom Nov 17, 2024
Merged
Conversation
Contributor
|
Glyphack
commented
Nov 17, 2024
| pub enum KnownInstanceType<'db> { | ||
| /// The symbol `typing.Literal` (which can also be found as `typing_extensions.Literal`) | ||
| Literal, | ||
| /// The symbol `typing.Optional` (which can also be found as `typing_extensions.Literal`) |
Contributor
Author
There was a problem hiding this comment.
Should this comment be repeated on every special form? Most of them have this properties.
Member
There was a problem hiding this comment.
I find the doc-comments helpful. It's true that many will likely be quite similar, but the comment for an enum variant shows up in the tooltip when you hover over that enum variant in your IDE with the ruff repo open
MichaReiser
reviewed
Nov 17, 2024
Co-authored-by: Micha Reiser <[email protected]>
typing.Optional in annotations
dhruvmanila
reviewed
Nov 17, 2024
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.
Fix: #14354
Summary
Recognize
Optionalspecial form in annotation. Bothtypingandtyping_extensionsmodules are valid for importingOptional.The result type is a Union with
None.Test Plan
Added tests for importing from modules and assignability and different combinations for the
Optionalparameter.