mirror of
https://github.com/astral-sh/ruff
synced 2026-01-06 22:24:05 -05:00
[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>
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
# parse_options: {"mode": "ipython"}
|
||||
with (a, ?b)
|
||||
?
|
||||
@@ -0,0 +1,3 @@
|
||||
# parse_options: {"mode": "ipython"}
|
||||
with (a, ?b
|
||||
?
|
||||
@@ -0,0 +1,4 @@
|
||||
# parse_options: {"mode": "ipython"}
|
||||
with a, ?b
|
||||
?
|
||||
x = 1
|
||||
Reference in New Issue
Block a user