Refactor range from Attributed to Nodes (#4422)

This commit is contained in:
Micha Reiser 2023-05-16 08:36:32 +02:00 committed by GitHub
parent 140e0acf54
commit fa26860296
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
330 changed files with 4816 additions and 3946 deletions

View file

@ -1,19 +1,19 @@
use rustpython_parser::ast::{self, Expr, Stmt, StmtKind};
use rustpython_parser::ast::{self, Expr, Stmt};
pub fn name(stmt: &Stmt) -> &str {
match &stmt.node {
StmtKind::FunctionDef(ast::StmtFunctionDef { name, .. })
| StmtKind::AsyncFunctionDef(ast::StmtAsyncFunctionDef { name, .. }) => name.as_str(),
_ => panic!("Expected StmtKind::FunctionDef | StmtKind::AsyncFunctionDef"),
match stmt {
Stmt::FunctionDef(ast::StmtFunctionDef { name, .. })
| Stmt::AsyncFunctionDef(ast::StmtAsyncFunctionDef { name, .. }) => name.as_str(),
_ => panic!("Expected Stmt::FunctionDef | Stmt::AsyncFunctionDef"),
}
}
pub fn decorator_list(stmt: &Stmt) -> &Vec<Expr> {
match &stmt.node {
StmtKind::FunctionDef(ast::StmtFunctionDef { decorator_list, .. })
| StmtKind::AsyncFunctionDef(ast::StmtAsyncFunctionDef { decorator_list, .. }) => {
pub fn decorator_list(stmt: &Stmt) -> &[Expr] {
match stmt {
Stmt::FunctionDef(ast::StmtFunctionDef { decorator_list, .. })
| Stmt::AsyncFunctionDef(ast::StmtAsyncFunctionDef { decorator_list, .. }) => {
decorator_list
}
_ => panic!("Expected StmtKind::FunctionDef | StmtKind::AsyncFunctionDef"),
_ => panic!("Expected Stmt::FunctionDef | Stmt::AsyncFunctionDef"),
}
}