[red-knot] Add Type::bool and boolean expression inference#13449
[red-knot] Add Type::bool and boolean expression inference#13449AlexWaygood merged 14 commits intoastral-sh:mainfrom
Type::bool and boolean expression inference#13449Conversation
|
carljm
left a comment
There was a problem hiding this comment.
Thank you, this is awesome! I think there's one bug, a couple tests that would be good to add, and I think we can also avoid allocating vectors in infer_boolean_expression.
|
Thanks for these great comments, I'll address them soon. Something else I was thinking about is to use What do you think about this? Should we do that? Maybe in another PR? |
Yes, that's something we will want. Definitely recommend separate PR for this, as there will be some decisions to make there about how to detect that we are calling the builtin bool type. |
AlexWaygood
left a comment
There was a problem hiding this comment.
nit: I prefer to use ::from methods rather than .into() methods where possible, as it's much clearer when reading things outside of an IDE what exactly you're converting the type into
carljm
left a comment
There was a problem hiding this comment.
This looks great to me! Thank you!!
|
Thanks again for your well explained and welcoming comments |
Type::bool and boolean expression inference
## Summary Following #13449, this PR adds custom handling for the bool constructor, 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 of `bool`. ```python x = bool(1) ``` ## Test Plan Some cargo tests were added.
Summary
Add boolean operator (
andandor) support for several types. I'm pretty new to Rust so any feedback would be great.A new
Type::boolfunction is created which may also help in #13432 as well.Contributes to #12701
Test Plan
Cargo tests