Integrate the new Jupyter AST nodes in Ruff (#6086)

## Summary

This PR adds the implementation for the new Jupyter AST nodes i.e.,
`ExprLineMagic` and `StmtLineMagic`.

## Test Plan

Add test cases for `unparse` containing magic commands

resolves: #6087
This commit is contained in:
Dhruv Manilawala 2023-07-26 13:50:30 +05:30 committed by GitHub
parent 1fdadee59c
commit 025fa4eba8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 228 additions and 19 deletions

View file

@ -92,6 +92,7 @@ impl FormatRule<Expr, PyFormatContext<'_>> for FormatExpr {
Expr::List(expr) => expr.format().fmt(f),
Expr::Tuple(expr) => expr.format().fmt(f),
Expr::Slice(expr) => expr.format().fmt(f),
Expr::LineMagic(_) => todo!(),
});
let parenthesize = match parentheses {
@ -233,6 +234,7 @@ impl NeedsParentheses for Expr {
Expr::List(expr) => expr.needs_parentheses(parent, context),
Expr::Tuple(expr) => expr.needs_parentheses(parent, context),
Expr::Slice(expr) => expr.needs_parentheses(parent, context),
Expr::LineMagic(_) => todo!(),
}
}
}
@ -405,6 +407,7 @@ impl<'input> CanOmitOptionalParenthesesVisitor<'input> {
| Expr::Starred(_)
| Expr::Name(_)
| Expr::Slice(_) => {}
Expr::LineMagic(_) => todo!(),
};
walk_expr(self, expr);

View file

@ -66,6 +66,7 @@ impl FormatRule<Stmt, PyFormatContext<'_>> for FormatStmt {
Stmt::Break(x) => x.format().fmt(f),
Stmt::Continue(x) => x.format().fmt(f),
Stmt::TypeAlias(x) => x.format().fmt(f),
Stmt::LineMagic(_) => todo!(),
}
}
}