ruff/crates/ruff_python_parser/src/parser
Dan Parizher 474b00568a
[`parser`] Fix panic when parsing IPython escape command expressions (#21480)
## Summary

Fixes a panic when parsing IPython escape commands with `Help` kind
(`?`) in expression contexts. The parser now reports an error instead of
panicking.

Fixes #21465.

## Problem

The parser panicked with `unreachable!()` in
`parse_ipython_escape_command_expression` when encountering escape
commands with `Help` kind (`?`) in expression contexts, where only
`Magic` (`%`) and `Shell` (`!`) are allowed.

## Approach

Replaced the `unreachable!()` panic with error handling that adds a
`ParseErrorType::OtherError` and continues parsing, returning a valid
AST node with the error attached.

## Test Plan

Added `test_ipython_escape_command_in_with_statement` and
`test_ipython_help_escape_command_as_expression` to verify the fix.

---------

Co-authored-by: Dhruv Manilawala <dhruvmanila@gmail.com>
2025-11-24 05:40:27 +00:00
..
snapshots Improved error recovery for unclosed strings (including f- and t-strings) (#20848) 2025-10-15 09:50:56 +02:00
expression.rs Catch syntax errors in nested interpolations before Python 3.12 (#20949) 2025-10-20 09:03:13 -04:00
helpers.rs Update Rust toolchain to 1.89 (#19807) 2025-08-07 18:21:50 +02:00
mod.rs [`parser`] Fix panic when parsing IPython escape command expressions (#21480) 2025-11-24 05:40:27 +00:00
options.rs [syntax-errors] Store to or delete `__debug__` (#16984) 2025-03-29 12:07:20 -04:00
pattern.rs [ty] Shrink size of `AstNodeRef` (#20028) 2025-08-22 17:03:22 -04:00
progress.rs Replace LALRPOP parser with hand-written parser (#10036) 2024-04-18 17:57:39 +05:30
recovery.rs [ty] AST garbage collection (#18482) 2025-06-13 08:40:11 -04:00
statement.rs Fix syntax error false positives on parenthesized context managers (#20846) 2025-10-13 14:13:27 -04:00
tests.rs Fix `unreachable` panic in parser (#19183) 2025-07-20 22:04:14 +00:00