FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

feat: add IndexExpr support to `constant_fold_expr` [1/2] by BobTheBuidler · Pull Request #19982 · python/mypy · GitHub

Repository navigation

feat: add IndexExpr support to constant_fold_expr [1/2] - #19982

Open
BobTheBuidler wants to merge 50 commits into
python:masterfrom
BobTheBuidler:patch-12
Open

BobTheBuidler wants to merge 50 commits into
python:masterfrom
BobTheBuidler:patch-12

Conversation

BobTheBuidler commented Oct 2, 2025 •
edited
Loading

Copy link
Copy Markdown
Contributor

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

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 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 marked this pull request as ready for review October 2, 2025 06:51

This comment has been minimized.

This comment has been minimized.

JukkaL left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Please add some test cases -- the logic is non-trivial so it would be good to have test coverage.

Comment thread mypy/constant_fold.py
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
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

Copy link
Copy Markdown
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?

This comment has been minimized.

BobTheBuidler marked this pull request as draft October 2, 2025 19:04

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.

hauntsaninja left a comment •
edited
Loading

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Jukka's comment about checking base is a sequence still applies, right?

Copy link
Copy Markdown
Contributor Author

Sequence / dict, yeah. It isn't just Sequence because #19864 enables quasi-folding over dicts

This comment has been minimized.

Copy link
Copy Markdown
Contributor

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

BobTheBuidler commented Feb 8, 2026 •
edited
Loading

Copy link
Copy Markdown
Contributor Author

@hauntsaninja did I perhaps misunderstand what you were asking about? Anything still blocking this one?

hauntsaninja commented Feb 8, 2026 •
edited
Loading

Copy link
Copy Markdown
Collaborator

Yeah, I understood Jukka's suggestion to be to use if isinstance(base, (Sequence, Mapping)) etc to avoid the type ignore comments on L102 and L109 #19982 (comment)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants


Back | FazBrowse Home | New Git URL