-
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] Literal[True,False]
normalized to builtins.bool
#13178
Conversation
Note: Attempting to call ruff/crates/red_knot_python_semantic/src/module_resolver/resolver.rs Lines 545 to 550 in 3ceedf7
If that's unexpected I can open an issue. |
|
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!!
It's not great that we can create a TestDb without a Program which will then panic in some cases; it'd be ideal if creating a TestDb always created a fully functional db, or if the lack of a Program were handled more gracefully than a panic. Thanks for catching that! I can create an issue for it later; should be addressed separately.
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.
Looks great!
fn simplify(&mut self) { | ||
if self | ||
.elements | ||
.is_superset(&[Type::BooleanLiteral(true), Type::BooleanLiteral(false)].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.
nice approach!
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.
It would be interesting to look at the generated code. into
creates an OrderSet
which in turn allocates.
I prefer using self.elements.contains(Type::BooleanLiteral(true) && self.elements.contains(Type::BooleanLiteral(false))
, which does not depend on the compiler being able to see through that the allocation isn't necessary (which requires rather involved analysis)
The
UnionBuilder
buildsbuiltins.bool
when handedLiteral[True]
andLiteral[False]
.Caveat: If the builtins module is unfindable somehow, the builder falls back to the union type of these two literals.
First task from #12694