Skip to content

Conversation

BobTheBuidler
Copy link
Contributor

This PR implements constant folding in StringFormatterChecker.checkers_for_c_type

@BobTheBuidler BobTheBuidler changed the title feat: support constant folding in StringFormatterChecker.checkers_for_c_type feat: support constant folding in StringFormatterChecker.checkers_for_c_type [1/1] Oct 2, 2025

This comment has been minimized.

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):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

note to self: can I get cur_mod_id from context?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Collaborator

@JukkaL JukkaL left a comment

Choose a reason for hiding this comment

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

Please add a mypy checker test case.

@BobTheBuidler
Copy link
Contributor Author

BobTheBuidler commented Oct 4, 2025

I forgot I can't use Final for my test here since we don't pass cur_mod_id into the constant_fold_expr call (should we? where can I get it from?) so my current test is not good.

But once we merge #19982 I can do a simple "abc"[1] for the test for this PR

This comment has been minimized.

Copy link
Contributor

github-actions bot commented Oct 6, 2025

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants