-
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 the return value of bool() #13538
Conversation
CodSpeed Performance ReportMerging #13538 will not alter performanceComparing Summary
|
db9a684
to
41a7c5a
Compare
|
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.
Thank you!! This looks like the right behavior, but the implementation should go inside Type::call
.
return if function_type == builtins_symbol_ty(self.db, "bool") { | ||
self.infer_bool_call_expression(arg_types.as_slice()) |
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.
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.
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.