Red Knot - Infer the return value of bool() #13538
Merged
carljm merged 3 commits intoastral-sh:mainfrom Sep 27, 2024
Merged
Conversation
CodSpeed Performance ReportMerging #13538 will not alter performanceComparing Summary
|
db9a684 to
41a7c5a
Compare
Contributor
|
carljm
requested changes
Sep 27, 2024
Contributor
carljm
left a comment
There was a problem hiding this comment.
Thank you!! This looks like the right behavior, but the implementation should go inside Type::call.
Comment on lines
+2033
to
+2034
| return if function_type == builtins_symbol_ty(self.db, "bool") { | ||
| self.infer_bool_call_expression(arg_types.as_slice()) |
Contributor
There was a problem hiding this comment.
This should happen inside Type::call instead of here, and it should use FunctionType::is_stdlib_symbol instead of querying the builtin type and comparing for equality.
Slyces
reviewed
Sep 27, 2024
carljm
approved these changes
Sep 27, 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.
Summary
Following #13449, this PR adds custom handling for the bool contractor, so when the input type has statically known truthiness value, it will be used as the return value of the bool function.
For example, in the following snippet x will now be resolved to
Literal[True]instead ofbool.Test Plan
Some cargo tests were added.