-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
[mypyc] feat: try constant fold in convert_format_expr_to_str
#20092
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
base: master
Are you sure you want to change the base?
Conversation
| if is_str_rprimitive(node_type) or isinstance(x, StrExpr): | ||
| # NOTE: why does mypyc think our fake StrExprs are not str rprimitives? | ||
| var_str = builder.accept(x) | ||
| elif (folded := constant_fold_expr(builder, x)) is not None: |
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.
foldable non-string values can be easily converted to str
| var_str = builder.primitive_op(str_op, [builder.accept(x)], line) | ||
| elif format_op == FormatOp.INT: | ||
| if is_int_rprimitive(node_type) or is_short_int_rprimitive(node_type): | ||
| if isinstance(folded := constant_fold_expr(builder, x), int): |
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.
if the expr can fold as an int we can convert it to str at build time
|
These tests should start working once #19982 is merged |
This reverts commit 7345e20.
No description provided.