| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
There aren't any tests but being able to do nested for loops seems like a pretty big win to me so I'm going to put up for review. The original returned boolean clearly had **false positives** for detecting bad errors for things like nested `if` and `for` statements. What is less clear is if there are any **true positives** which I am no longer catching with the updated return value.
WalkthroughUpdates shell_exec’s error handling in src/shell.rs: for OtherError messages starting with "Expected an indented block", the REPL now always returns ContinueBlock, independent of continuing_block. IndentationError handling remains tied to continuing_block; other errors still yield PyErr. Changes
Sequence Diagram(s)sequenceDiagram
participant U as User
participant R as REPL
participant P as Parser
participant H as Error Handler (shell_exec)
U->>R: Enter code
R->>P: Parse input
P-->>H: Error
alt IndentationError
H->>H: Use continuing_block to decide
H-->>R: ContinueBlock or PyErr
else OtherError starts with "Expected an indented block"
H-->>R: ContinueBlock (always)
else OtherError (other)
H-->>R: PyErr
end
R-->>U: Outcome
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.
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 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type @coderabbitai help to get the list of available commands. Other keywords and placeholders
Status, Documentation and Community
|
Sorry, something went wrong.
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (3)src/shell.rs (3)📜 Review details77-81: Refresh the comment to match the actual behavior and remove stale ‘dedent’ note
The current comment mentions column checks and dedent handling that aren’t reflected in the code anymore. Updating the comment helps future maintainers.
Apply this diff to align the comment with the current logic:
- // bad_error == true if we are handling an error that should be thrown even if we are continuing - // if its an indentation error, set to true if we are continuing and the error is on column 0, - // since indentations errors on columns other than 0 should be ignored. - // if its an unrecognized token for dedent, set to false + // bad_error is true when the error should be raised immediately (fatal), even while building a block. + // - IndentationError: fatal iff we are already continuing a block (pressing an empty line still raises). + // - "Expected an indented block": non-fatal — always ContinueBlock to allow nested/nested blocks. + // - All other parse errors: fatal.
82-95: Avoid brittle string literal; centralize the prefix used for detection
To reduce the risk of typos and make future updates easier if the message text changes slightly, centralize the prefix in a constant and reference it here.
Apply this diff within this match arm:
- ParseErrorType::OtherError(msg) => { - !msg.starts_with("Expected an indented block") - } + ParseErrorType::OtherError(msg) => { + !msg.starts_with(EXPECTED_INDENTED_BLOCK_PREFIX) + }Add this constant near the top of the file (e.g., after imports):
const EXPECTED_INDENTED_BLOCK_PREFIX: &str = "Expected an indented block";
97-103: Add targeted tests to lock in behavior (nested blocks and blank-line error)
The new behavior is desirable; please add tests that assert:
- ContinueBlock after a single “for …:” line.
- ContinueBlock after a nested “for …:” line when already in a continuing block.
- PyErr when an empty line is submitted while still expecting an indented block (matches CPython).
I can help scaffold tests around shell_exec in a #[cfg(test)] module to exercise these cases.
Would you like me to draft the tests?
Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
You can enable these sources in your CodeRabbit configuration.
📥 CommitsReviewing files that changed from the base of the PR and between a9a9e3b and 135ccae.
📒 Files selected for processing (1)📄 CodeRabbit Inference Engine (.github/copilot-instructions.md)
**/*.rs: Follow the default rustfmt code style (cargo fmt to format)
Always run clippy to lint code (cargo clippy) before completing tasks. Fix any warnings or lints that are introduced by your changes
Follow Rust best practices for error handling and memory management
Use the macro system (pyclass, pymodule, pyfunction, etc.) when implementing Python functionality in Rust
Files:
src/shell.rs (2)88-90: Always ContinueBlock on “Expected an indented block” — correct fix to enable nested blocks
This change ensures nested for/if blocks are accepted even when already inside a continuing block. The blank-line case still raises (due to the empty_line_given check), which matches CPython REPL behavior.
88-90: Update error-check prefix to match parser output
The guard in src/shell.rs is using the truncated prefix "Expected an indented block", but the parser emits "Expected an indented block after". This mismatch causes the intended errors to slip through.
• src/shell.rs:89
- !msg.starts_with("Expected an indented block") + !msg.starts_with("Expected an indented block after")Likely an incorrect or invalid review comment.
Sorry, something went wrong.
@arihant2math Could you please guide how to contribute more on ctypes? The previous ongoing work was #5653 |
Sorry, something went wrong.
There was a problem hiding this comment.
Thank you!
If you are interested in, This error probably be introduced in commit a6b4ef7
Sorry, something went wrong.
|
@youknowone ... it mostly requires following what is being done by the external cpython api (ie test suites and examples). For various reasons, following cpythons approach to ffi is unsafe and not suitable to be done in rust, so my suggestion is to pick an example and trying to get it functional. It's also highly unsafe so there will be many weird memory corruption bugs. I'd probably caution against using too much AI for that reason. |
Sorry, something went wrong.
|
Thanks for sharing the draft ctypes PR! I have a better idea of its scope now and I'll check out the PR in detail and see if I can follow what's going on later 🙇 |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Description
Allow nested indented blocks in RustPython REPL.
Additional comments
There aren't any tests but being able to do nested for loops seems like a pretty big win to me so I'm going to put up for review.
The original returned boolean clearly had false positives for detecting bad errors for things like nested if and for statements. What is less clear is if there are any true positives which I am no longer catching with the updated return value.
Questions
I have seen reference to something called ctypes that if fixed would allow the use of pyrepl which is implemented in Python. Is there any way I could help with the ctypes work?
Manual testing
Before
After
Summary by CodeRabbit