mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-16 16:40:36 +00:00
Rename Magic*
to IpyEscape*
(#6395)
## Summary This PR renames the `MagicCommand` token to `IpyEscapeCommand` token and `MagicKind` to `IpyEscapeKind` type to better reflect the purpose of the token and type. Similarly, it renames the AST nodes from `LineMagic` to `IpyEscapeCommand` prefixed with `Stmt`/`Expr` wherever necessary. It also makes renames from using `jupyter_magic` to `ipython_escape_commands` in various function names. The mode value is still `Mode::Jupyter` because the escape commands are part of the IPython syntax but the lexing/parsing is done for a Jupyter notebook. ### Motivation behind the rename: * IPython codebase defines it as "EscapeCommand" / "Escape Sequences": * Escape Sequences:292e3a2345/IPython/core/inputtransformer2.py (L329-L333)
* Escape command:292e3a2345/IPython/core/inputtransformer2.py (L410-L411)
* The word "magic" is used mainly for the actual magic commands i.e., the ones starting with `%`/`%%` (https://ipython.readthedocs.io/en/stable/interactive/reference.html#magic-command-system). So, this avoids any confusion between the Magic token (`%`, `%%`) and the escape command itself. ## Test Plan * `cargo test` to make sure all renames are done correctly. * `grep` for `jupyter_escape`/`magic` to make sure all renames are done correctly.
This commit is contained in:
parent
3bf1c66cda
commit
6a64f2289b
26 changed files with 949 additions and 946 deletions
|
@ -117,7 +117,7 @@ pub fn parse_expression_starts_at(
|
|||
///
|
||||
/// This function is the most general function to parse Python code. Based on the [`Mode`] supplied,
|
||||
/// it can be used to parse a single expression, a full Python program, an interactive expression
|
||||
/// or a Python program containing Jupyter magics.
|
||||
/// or a Python program containing IPython escape commands.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
|
@ -146,7 +146,7 @@ pub fn parse_expression_starts_at(
|
|||
/// assert!(program.is_ok());
|
||||
/// ```
|
||||
///
|
||||
/// Additionally, we can parse a Python program containing Jupyter magics:
|
||||
/// Additionally, we can parse a Python program containing IPython escapes:
|
||||
///
|
||||
/// ```
|
||||
/// use ruff_python_parser::{Mode, parse};
|
||||
|
@ -1122,7 +1122,7 @@ class Abcd:
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn test_jupyter_magic() {
|
||||
fn test_ipython_escape_commands() {
|
||||
let parse_ast = parse(
|
||||
r#"
|
||||
# Normal Python code
|
||||
|
@ -1169,7 +1169,7 @@ def foo():
|
|||
;foo 1 2
|
||||
,foo 1 2
|
||||
|
||||
# Indented magic
|
||||
# Indented escape commands
|
||||
for a in range(5):
|
||||
!ls
|
||||
|
||||
|
@ -1199,7 +1199,7 @@ foo.bar[0].baz[2].egg??
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn test_jupyter_magic_parse_error() {
|
||||
fn test_ipython_escape_command_parse_error() {
|
||||
let source = r#"
|
||||
a = 1
|
||||
%timeit a == 1
|
||||
|
@ -1209,7 +1209,7 @@ a = 1
|
|||
let parse_err = parse_tokens(lxr, Mode::Module, "<test>").unwrap_err();
|
||||
assert_eq!(
|
||||
parse_err.to_string(),
|
||||
"line magics are only allowed in Jupyter mode at byte offset 6".to_string()
|
||||
"IPython escape commands are only allowed in Jupyter mode at byte offset 6".to_string()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue