mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-01 06:11:43 +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
|
@ -672,8 +672,8 @@ pub struct ExprSlice<'a> {
|
|||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Hash)]
|
||||
pub struct ExprLineMagic<'a> {
|
||||
kind: ast::MagicKind,
|
||||
pub struct ExprIpyEscapeCommand<'a> {
|
||||
kind: ast::IpyEscapeKind,
|
||||
value: &'a str,
|
||||
}
|
||||
|
||||
|
@ -706,7 +706,7 @@ pub enum ComparableExpr<'a> {
|
|||
List(ExprList<'a>),
|
||||
Tuple(ExprTuple<'a>),
|
||||
Slice(ExprSlice<'a>),
|
||||
LineMagic(ExprLineMagic<'a>),
|
||||
IpyEscapeCommand(ExprIpyEscapeCommand<'a>),
|
||||
}
|
||||
|
||||
impl<'a> From<&'a Box<ast::Expr>> for Box<ComparableExpr<'a>> {
|
||||
|
@ -936,11 +936,11 @@ impl<'a> From<&'a ast::Expr> for ComparableExpr<'a> {
|
|||
upper: upper.as_ref().map(Into::into),
|
||||
step: step.as_ref().map(Into::into),
|
||||
}),
|
||||
ast::Expr::LineMagic(ast::ExprLineMagic {
|
||||
ast::Expr::IpyEscapeCommand(ast::ExprIpyEscapeCommand {
|
||||
kind,
|
||||
value,
|
||||
range: _,
|
||||
}) => Self::LineMagic(ExprLineMagic {
|
||||
}) => Self::IpyEscapeCommand(ExprIpyEscapeCommand {
|
||||
kind: *kind,
|
||||
value: value.as_str(),
|
||||
}),
|
||||
|
@ -1165,8 +1165,8 @@ pub struct StmtExpr<'a> {
|
|||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Hash)]
|
||||
pub struct StmtLineMagic<'a> {
|
||||
kind: ast::MagicKind,
|
||||
pub struct StmtIpyEscapeCommand<'a> {
|
||||
kind: ast::IpyEscapeKind,
|
||||
value: &'a str,
|
||||
}
|
||||
|
||||
|
@ -1193,7 +1193,7 @@ pub enum ComparableStmt<'a> {
|
|||
ImportFrom(StmtImportFrom<'a>),
|
||||
Global(StmtGlobal<'a>),
|
||||
Nonlocal(StmtNonlocal<'a>),
|
||||
LineMagic(StmtLineMagic<'a>),
|
||||
IpyEscapeCommand(StmtIpyEscapeCommand<'a>),
|
||||
Expr(StmtExpr<'a>),
|
||||
Pass,
|
||||
Break,
|
||||
|
@ -1394,11 +1394,11 @@ impl<'a> From<&'a ast::Stmt> for ComparableStmt<'a> {
|
|||
names: names.iter().map(ast::Identifier::as_str).collect(),
|
||||
})
|
||||
}
|
||||
ast::Stmt::LineMagic(ast::StmtLineMagic {
|
||||
ast::Stmt::IpyEscapeCommand(ast::StmtIpyEscapeCommand {
|
||||
kind,
|
||||
value,
|
||||
range: _,
|
||||
}) => Self::LineMagic(StmtLineMagic {
|
||||
}) => Self::IpyEscapeCommand(StmtIpyEscapeCommand {
|
||||
kind: *kind,
|
||||
value: value.as_str(),
|
||||
}),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue