Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[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

Merged
JukkaL merged 35 commits intopython:masterfromBobTheBuidler:patch-3
Aug 15, 2025

Conversation

@BobTheBuidler
Copy link
Contributor

@BobTheBuidlerBobTheBuidler commentedAug 7, 2025
edited
Loading

We can do some extra constant folding in cases like this:

fromtypingimportFinalBASE_URL:Final="https://example.com"PORT:Final=1234defget_url(endpoint:str)->str:returnf"{BASE_URL}:{PORT}/{endpoint}"

which should generate the same C code as

defget_url(endpoint:str)->str:returnf"https://example.com:1234/{endpoint}"

This PR makes it so.

@BobTheBuidlerBobTheBuidler changed the titleWIP [mypyc] optimize f-string building[mypyc] feat: optimize f-string building from Final valuesAug 11, 2025
@BobTheBuidlerBobTheBuidler marked this pull request as ready for reviewAugust 11, 2025 22:05
@BobTheBuidler
Copy link
ContributorAuthor

This PR is now ready for review.

@BobTheBuidler
Copy link
ContributorAuthor

BobTheBuidler commentedAug 11, 2025
edited
Loading

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.

Copy link
Collaborator

@JukkaLJukkaL left a 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.

@BobTheBuidler
Copy link
ContributorAuthor

Thanks for your feedbacks. Tests added, comment removed.

@JukkaLJukkaL merged commitac646c0 intopython:masterAug 15, 2025
13 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@JukkaLJukkaLJukkaL approved these changes

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@BobTheBuidler@JukkaL

[8]ページ先頭

©2009-2025 Movatter.jp