Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork3.1k
[mypyc] feat: optimize f-string building from Final values#19611
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
for more information, seehttps://pre-commit.ci
for more information, seehttps://pre-commit.ci
BobTheBuidler commentedAug 11, 2025
This PR is now ready for review. |
for more information, seehttps://pre-commit.ci
for more information, seehttps://pre-commit.ci
BobTheBuidler commentedAug 11, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
This can probably be extended later on for non-final values that type check as Literals ex: deftest():abcd="abcd"efgh="efgh"ifsome_check():ijkl="ijkl0"some_numbers=123returnf"{abcd}{efgh}{ijkl}{some_numbers}{some_fn()}"else:ijkl="ijkl1"some_numbers=456returnf"{abcd}{efgh}{ijkl}{some_numbers}{some_fn()}" But I think that goes beyond the scope of this PR. Once we merge this it will be easy to modify the literal helper fn. |
JukkaL left a comment
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 for the PR! The approach looks good, just a few minor comments.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
BobTheBuidler commentedAug 13, 2025
Thanks for your feedbacks. Tests added, comment removed. |
ac646c0 intopython:masterUh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
We can do some extra constant folding in cases like this:
which should generate the same C code as
This PR makes it so.