FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[mypyc] feat: try constant fold in `convert_format_expr_to_str` by BobTheBuidler · Pull Request #20092 · python/mypy · GitHub

Repository navigation

[mypyc] feat: try constant fold in convert_format_expr_to_str - #20092

Open
BobTheBuidler wants to merge 9 commits into
python:masterfrom
BobTheBuidler:patch-22
Open

BobTheBuidler wants to merge 9 commits into
python:masterfrom
BobTheBuidler:patch-22

Conversation

Copy link
Copy Markdown
Contributor

No description provided.

Comment thread mypyc/irbuild/format_str_tokenizer.py Outdated
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:

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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):

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

if the expr can fold as an int we can convert it to str at build time

Copy link
Copy Markdown
Contributor Author

These tests should start working once #19982 is merged

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants


Back | FazBrowse Home | New Git URL