feat: support constant folding in StringFormatterChecker.checkers_for_c_type [1/1]#19978
Open
BobTheBuidler wants to merge 8 commits into
Open
feat: support constant folding in StringFormatterChecker.checkers_for_c_type [1/1]#19978BobTheBuidler wants to merge 8 commits into
StringFormatterChecker.checkers_for_c_type [1/1]#19978BobTheBuidler wants to merge 8 commits into
Conversation
StringFormatterChecker.checkers_for_c_typeStringFormatterChecker.checkers_for_c_type [1/1]
This comment has been minimized.
This comment has been minimized.
BobTheBuidler
commented
Oct 2, 2025
| self.msg.requires_int_or_single_byte(context) | ||
| elif isinstance(expr, (StrExpr, BytesExpr)) and len(expr.value) != 1: | ||
| self.msg.requires_int_or_char(context) | ||
| elif isinstance(folded := constant_fold_expr(expr, "<unused>"), str): |
Contributor
Author
There was a problem hiding this comment.
note to self: can I get cur_mod_id from context?
Contributor
Author
There was a problem hiding this comment.
I think we need to pass cur_mod_id here for this PR to work properly. I'm just not entirely sure how we can get access to it here.
This comment has been minimized.
This comment has been minimized.
JukkaL
reviewed
Oct 2, 2025
JukkaL
left a comment
Collaborator
There was a problem hiding this comment.
Please add a mypy checker test case.
Contributor
Author
|
I forgot I can't use Final for my test here since we don't pass But once we merge #19982 I can do a simple |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Contributor
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
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
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR implements constant folding in
StringFormatterChecker.checkers_for_c_type