Skip to content

Conversation

@BobTheBuidler
Copy link
Contributor

@BobTheBuidler BobTheBuidler commented Oct 2, 2025

This PR adds support for IndexExpr in constant_fold_expr and support for constant folding in transform_index_expr

@BobTheBuidler BobTheBuidler changed the title [mypyc] feat: add IndexOp support to constant_fold_expr [mypyc] feat: add IndexExpr support to constant_fold_expr [1/1] Oct 2, 2025
@BobTheBuidler BobTheBuidler changed the title [mypyc] feat: add IndexExpr support to constant_fold_expr [1/1] feat: add IndexExpr support to constant_fold_expr [1/1] Oct 2, 2025
@BobTheBuidler BobTheBuidler marked this pull request as ready for review October 2, 2025 06:51
@github-actions

This comment has been minimized.

@github-actions

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 some test cases -- the logic is non-trivial so it would be good to have test coverage.

return constant_fold_unary_op(expr.op, value)
elif isinstance(expr, IndexExpr):
base = constant_fold_expr(expr.base, cur_mod_id)
if base is not None:
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it would be better to check if base is a Sequence -- you can index an int, for example.

@BobTheBuidler
Copy link
Contributor Author

If we can merge #19930 first I would be able to re-use the same run test, I think that's probably best for the sake of deduplication. Wdyt?

@github-actions

This comment has been minimized.

@BobTheBuidler BobTheBuidler marked this pull request as draft October 2, 2025 19:04
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@BobTheBuidler BobTheBuidler changed the title feat: add IndexExpr support to constant_fold_expr [1/1] feat: add IndexExpr support to constant_fold_expr [1/2] Oct 14, 2025
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 6, 2026

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants