-
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] Add Type::bool
and boolean expression inference
#13449
[red-knot] Add Type::bool
and boolean expression inference
#13449
Conversation
|
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.
Nice, thank you! Not a complete review (I'm on holiday at the moment), just a couple of things I spotted:
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.
Nice!
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 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. |
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.
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
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 looks great to me! Thank you!!
Thanks again for your well explained and welcoming comments |
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.
Thanks! :-D
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 (
and
andor
) support for several types. I'm pretty new to Rust so any feedback would be great.A new
Type::bool
function is created which may also help in #13432 as well.Contributes to #12701
Test Plan
Cargo tests