-
-
Notifications
You must be signed in to change notification settings - Fork 3k
[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 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
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
This PR is now ready for review. |
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
This can probably be extended later on for non-final values that type check as Literals ex: def test():
abcd = "abcd"
efgh = "efgh"
if some_check():
ijkl = "ijkl0"
some_numbers = 123
return f"{abcd}{efgh}{ijkl}{some_numbers}{some_fn()}"
else:
ijkl = "ijkl1"
some_numbers = 456
return f"{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. |
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.
for more information, see https://pre-commit.ci
Thanks for your feedbacks. Tests added, comment removed. |
for more information, see https://pre-commit.ci
We can do some extra constant folding in cases like this:
which should generate the same C code as
This PR makes it so.