GeezerVison is showing github.com — Remove duplicated code in `compile.rs` by ShaharNaveh · Pull Request #8141 · RustPython/RustPython
Conversation
ShaharNaveh
commented
Jun 22, 2026
•
edited by coderabbitai
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
Summary
Summary by CodeRabbit
- Refactor
- Refactored constant expression detection logic to improve code organization and maintainability without affecting user-facing functionality.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
coderabbitai
Bot
commented
Jun 22, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|

No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Run ID: 7104264e-6bb8-4440-9a4f-b66b0a1f8b98
📥 Commits
Reviewing files that changed from the base of the PR and between 55b96f9 and 3bcfd74.
📒 Files selected for processing (1)
crates/codegen/src/compile.rs
📝 Walkthrough
Walkthrough
In compile.rs, the standalone is_const_expression helper function is removed. A new ExprExt trait method is_constant takes over constant-literal detection. The interactive-mode branch that guards Instruction::Nop emission is updated to call value.is_constant() instead of the removed helper.
Changes
Constant detection refactor in compile.rs
| Layer / File(s) |
Summary |
ExprExt contract, call site update, and helper removal crates/codegen/src/compile.rs |
Adds ExprExt::is_constant method contract, replaces Self::is_const_expression(value) with value.is_constant() in the interactive-mode Nop-guard branch, and removes the now-redundant is_const_expression(expr: &ast::Expr) -> bool helper function. |
Estimated code review effort
🎯 1 (Trivial) | ⏱️ ~3 minutes
Possibly related PRs
- RustPython/RustPython#7541: Directly related — both PRs touch the
ExprExt::is_constant method in crates/codegen/src/compile.rs, with that PR extending the semantics that this PR's call site now relies on.
Poem
🐇 A helper once lived in a function so plain,
Matching literals again and again.
Now the trait takes the wheel with is_constant in tow,
The old code deleted, the logic aglow.
Less is more, little bunny, hop hop away! 🌿
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
| Check name |
Status |
Explanation |
| Description Check |
✅ Passed |
Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title check |
✅ Passed |
The title accurately describes the main change: removing a duplicated is_const_expression function and consolidating constant-checking logic into an ExprExt extension trait method. |
| Docstring Coverage |
✅ Passed |
Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. |
| Linked Issues check |
✅ Passed |
Check skipped because no linked issues were found for this pull request. |
| Out of Scope Changes check |
✅ Passed |
Check skipped because no linked issues were found for this pull request. |
✏️ Tip: You can configure your own custom pre-merge checks in the settings.
✨ Finishing Touches
🧪 Generate unit tests (beta)
- Create PR with unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share
Comment @coderabbitai help to get the list of available commands and usage tips.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
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.