mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 18:28:56 +00:00
Remove visit_arg_with_default (#5265)
## Summary This is a follow up to #5221. Turns out it was easy to restructure the visitor to get the right order, I'm just dumb 🤷♂️ I've removed `visit_arg_with_default` entirely from the `Visitor`, although it still exists as part of `preorder::Visitor`.
This commit is contained in:
parent
62e2c46f98
commit
f194572be8
1 changed files with 21 additions and 17 deletions
|
@ -2,7 +2,7 @@
|
|||
|
||||
pub mod preorder;
|
||||
|
||||
use rustpython_ast::{ArgWithDefault, Decorator};
|
||||
use rustpython_ast::Decorator;
|
||||
use rustpython_parser::ast::{
|
||||
self, Alias, Arg, Arguments, BoolOp, CmpOp, Comprehension, Constant, ExceptHandler, Expr,
|
||||
ExprContext, Keyword, MatchCase, Operator, Pattern, Stmt, UnaryOp, WithItem,
|
||||
|
@ -61,9 +61,6 @@ pub trait Visitor<'a> {
|
|||
fn visit_arg(&mut self, arg: &'a Arg) {
|
||||
walk_arg(self, arg);
|
||||
}
|
||||
fn visit_arg_with_default(&mut self, arg_with_default: &'a ArgWithDefault) {
|
||||
walk_arg_with_default(self, arg_with_default);
|
||||
}
|
||||
fn visit_keyword(&mut self, keyword: &'a Keyword) {
|
||||
walk_keyword(self, keyword);
|
||||
}
|
||||
|
@ -606,17 +603,34 @@ pub fn walk_except_handler<'a, V: Visitor<'a> + ?Sized>(
|
|||
}
|
||||
|
||||
pub fn walk_arguments<'a, V: Visitor<'a> + ?Sized>(visitor: &mut V, arguments: &'a Arguments) {
|
||||
// Defaults are evaluated before annotations.
|
||||
for arg in &arguments.posonlyargs {
|
||||
visitor.visit_arg_with_default(arg);
|
||||
if let Some(default) = &arg.default {
|
||||
visitor.visit_expr(default);
|
||||
}
|
||||
}
|
||||
for arg in &arguments.args {
|
||||
visitor.visit_arg_with_default(arg);
|
||||
if let Some(default) = &arg.default {
|
||||
visitor.visit_expr(default);
|
||||
}
|
||||
}
|
||||
for arg in &arguments.kwonlyargs {
|
||||
if let Some(default) = &arg.default {
|
||||
visitor.visit_expr(default);
|
||||
}
|
||||
}
|
||||
|
||||
for arg in &arguments.posonlyargs {
|
||||
visitor.visit_arg(&arg.def);
|
||||
}
|
||||
for arg in &arguments.args {
|
||||
visitor.visit_arg(&arg.def);
|
||||
}
|
||||
if let Some(arg) = &arguments.vararg {
|
||||
visitor.visit_arg(arg);
|
||||
}
|
||||
for arg in &arguments.kwonlyargs {
|
||||
visitor.visit_arg_with_default(arg);
|
||||
visitor.visit_arg(&arg.def);
|
||||
}
|
||||
if let Some(arg) = &arguments.kwarg {
|
||||
visitor.visit_arg(arg);
|
||||
|
@ -629,16 +643,6 @@ pub fn walk_arg<'a, V: Visitor<'a> + ?Sized>(visitor: &mut V, arg: &'a Arg) {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn walk_arg_with_default<'a, V: Visitor<'a> + ?Sized>(
|
||||
visitor: &mut V,
|
||||
arg_with_default: &'a ArgWithDefault,
|
||||
) {
|
||||
if let Some(expr) = &arg_with_default.default {
|
||||
visitor.visit_expr(expr);
|
||||
}
|
||||
visitor.visit_arg(&arg_with_default.def);
|
||||
}
|
||||
|
||||
pub fn walk_keyword<'a, V: Visitor<'a> + ?Sized>(visitor: &mut V, keyword: &'a Keyword) {
|
||||
visitor.visit_expr(&keyword.value);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue