mirror of
https://github.com/astral-sh/ruff
synced 2026-01-09 23:54:36 -05:00
Rename Arguments to Parameters in the AST (#6253)
## Summary This PR renames a few AST nodes for clarity: - `Arguments` is now `Parameters` - `Arg` is now `Parameter` - `ArgWithDefault` is now `ParameterWithDefault` For now, the attribute names that reference `Parameters` directly are changed (e.g., on `StmtFunctionDef`), but the attributes on `Parameters` itself are not (e.g., `vararg`). We may revisit that decision in the future. For context, the AST node formerly known as `Arguments` is used in function definitions. Formally (outside of the Python context), "arguments" typically refers to "the values passed to a function", while "parameters" typically refers to "the variables used in a function definition". E.g., if you Google "arguments vs parameters", you'll get some explanation like: > A parameter is a variable in a function definition. It is a placeholder and hence does not have a concrete value. An argument is a value passed during function invocation. We're thus deviating from Python's nomenclature in favor of a scheme that we find to be more precise.
This commit is contained in:
@@ -4,13 +4,13 @@ use insta::assert_snapshot;
|
||||
|
||||
use ruff_python_ast::node::AnyNodeRef;
|
||||
use ruff_python_ast::visitor::preorder::{
|
||||
walk_alias, walk_arg, walk_arguments, walk_comprehension, walk_except_handler, walk_expr,
|
||||
walk_keyword, walk_match_case, walk_module, walk_pattern, walk_stmt, walk_type_param,
|
||||
walk_alias, walk_comprehension, walk_except_handler, walk_expr, walk_keyword, walk_match_case,
|
||||
walk_module, walk_parameter, walk_parameters, walk_pattern, walk_stmt, walk_type_param,
|
||||
walk_with_item, PreorderVisitor,
|
||||
};
|
||||
use ruff_python_ast::{
|
||||
Alias, Arg, Arguments, BoolOp, CmpOp, Comprehension, Constant, ExceptHandler, Expr, Keyword,
|
||||
MatchCase, Mod, Operator, Pattern, Stmt, TypeParam, UnaryOp, WithItem,
|
||||
Alias, BoolOp, CmpOp, Comprehension, Constant, ExceptHandler, Expr, Keyword, MatchCase, Mod,
|
||||
Operator, Parameter, Parameters, Pattern, Stmt, TypeParam, UnaryOp, WithItem,
|
||||
};
|
||||
use ruff_python_parser::lexer::lex;
|
||||
use ruff_python_parser::{parse_tokens, Mode};
|
||||
@@ -231,15 +231,15 @@ impl PreorderVisitor<'_> for RecordVisitor {
|
||||
self.exit_node();
|
||||
}
|
||||
|
||||
fn visit_arguments(&mut self, arguments: &Arguments) {
|
||||
self.enter_node(arguments);
|
||||
walk_arguments(self, arguments);
|
||||
fn visit_parameters(&mut self, parameters: &Parameters) {
|
||||
self.enter_node(parameters);
|
||||
walk_parameters(self, parameters);
|
||||
self.exit_node();
|
||||
}
|
||||
|
||||
fn visit_arg(&mut self, arg: &Arg) {
|
||||
self.enter_node(arg);
|
||||
walk_arg(self, arg);
|
||||
fn visit_parameter(&mut self, parameter: &Parameter) {
|
||||
self.enter_node(parameter);
|
||||
walk_parameter(self, parameter);
|
||||
self.exit_node();
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ expression: trace
|
||||
- ModModule
|
||||
- StmtFunctionDef
|
||||
- ExprName
|
||||
- Arguments
|
||||
- Parameters
|
||||
- StmtPass
|
||||
- StmtClassDef
|
||||
- ExprName
|
||||
|
||||
@@ -4,20 +4,20 @@ expression: trace
|
||||
---
|
||||
- ModModule
|
||||
- StmtFunctionDef
|
||||
- Arguments
|
||||
- Arg
|
||||
- Arg
|
||||
- Arg
|
||||
- Arg
|
||||
- Parameters
|
||||
- Parameter
|
||||
- Parameter
|
||||
- Parameter
|
||||
- Parameter
|
||||
- ExprConstant
|
||||
- Int(20)
|
||||
- Arg
|
||||
- Arg
|
||||
- Parameter
|
||||
- Parameter
|
||||
- ExprConstant
|
||||
- Int(5)
|
||||
- Arg
|
||||
- Parameter
|
||||
- ExprConstant
|
||||
- Int(20)
|
||||
- Arg
|
||||
- Parameter
|
||||
- StmtPass
|
||||
|
||||
|
||||
@@ -4,14 +4,14 @@ expression: trace
|
||||
---
|
||||
- ModModule
|
||||
- StmtFunctionDef
|
||||
- Arguments
|
||||
- Arg
|
||||
- Arg
|
||||
- Parameters
|
||||
- Parameter
|
||||
- Parameter
|
||||
- ExprConstant
|
||||
- Int(34)
|
||||
- Arg
|
||||
- Parameter
|
||||
- ExprConstant
|
||||
- Int(20)
|
||||
- Arg
|
||||
- Parameter
|
||||
- StmtPass
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ expression: trace
|
||||
- TypeParamTypeVar
|
||||
- TypeParamTypeVarTuple
|
||||
- TypeParamParamSpec
|
||||
- Arguments
|
||||
- Parameters
|
||||
- StmtExpr
|
||||
- ExprConstant
|
||||
- Ellipsis
|
||||
|
||||
@@ -4,7 +4,7 @@ expression: trace
|
||||
---
|
||||
- StmtFunctionDef
|
||||
- ExprName
|
||||
- Arguments
|
||||
- Parameters
|
||||
- StmtPass
|
||||
- StmtClassDef
|
||||
- ExprName
|
||||
|
||||
@@ -3,17 +3,17 @@ source: crates/ruff_python_ast/tests/visitor.rs
|
||||
expression: trace
|
||||
---
|
||||
- StmtFunctionDef
|
||||
- Arguments
|
||||
- Parameters
|
||||
- ExprConstant
|
||||
- ExprConstant
|
||||
- ExprConstant
|
||||
- Arg
|
||||
- Arg
|
||||
- Arg
|
||||
- Arg
|
||||
- Arg
|
||||
- Arg
|
||||
- Arg
|
||||
- Arg
|
||||
- Parameter
|
||||
- Parameter
|
||||
- Parameter
|
||||
- Parameter
|
||||
- Parameter
|
||||
- Parameter
|
||||
- Parameter
|
||||
- Parameter
|
||||
- StmtPass
|
||||
|
||||
|
||||
@@ -3,12 +3,12 @@ source: crates/ruff_python_ast/tests/visitor.rs
|
||||
expression: trace
|
||||
---
|
||||
- StmtFunctionDef
|
||||
- Arguments
|
||||
- Parameters
|
||||
- ExprConstant
|
||||
- ExprConstant
|
||||
- Arg
|
||||
- Arg
|
||||
- Arg
|
||||
- Arg
|
||||
- Parameter
|
||||
- Parameter
|
||||
- Parameter
|
||||
- Parameter
|
||||
- StmtPass
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ expression: trace
|
||||
- TypeParamTypeVar
|
||||
- TypeParamTypeVarTuple
|
||||
- TypeParamParamSpec
|
||||
- Arguments
|
||||
- Parameters
|
||||
- StmtExpr
|
||||
- ExprConstant
|
||||
|
||||
|
||||
@@ -7,13 +7,13 @@ use ruff_python_parser::{parse_tokens, Mode};
|
||||
|
||||
use ruff_python_ast::node::AnyNodeRef;
|
||||
use ruff_python_ast::visitor::{
|
||||
walk_alias, walk_arg, walk_arguments, walk_comprehension, walk_except_handler, walk_expr,
|
||||
walk_keyword, walk_match_case, walk_pattern, walk_stmt, walk_type_param, walk_with_item,
|
||||
walk_alias, walk_comprehension, walk_except_handler, walk_expr, walk_keyword, walk_match_case,
|
||||
walk_parameter, walk_parameters, walk_pattern, walk_stmt, walk_type_param, walk_with_item,
|
||||
Visitor,
|
||||
};
|
||||
use ruff_python_ast::{
|
||||
Alias, Arg, Arguments, BoolOp, CmpOp, Comprehension, ExceptHandler, Expr, Keyword, MatchCase,
|
||||
Operator, Pattern, Stmt, TypeParam, UnaryOp, WithItem,
|
||||
Alias, BoolOp, CmpOp, Comprehension, ExceptHandler, Expr, Keyword, MatchCase, Operator,
|
||||
Parameter, Parameters, Pattern, Stmt, TypeParam, UnaryOp, WithItem,
|
||||
};
|
||||
|
||||
#[test]
|
||||
@@ -234,15 +234,15 @@ impl Visitor<'_> for RecordVisitor {
|
||||
self.exit_node();
|
||||
}
|
||||
|
||||
fn visit_arguments(&mut self, arguments: &Arguments) {
|
||||
self.enter_node(arguments);
|
||||
walk_arguments(self, arguments);
|
||||
fn visit_parameters(&mut self, parameters: &Parameters) {
|
||||
self.enter_node(parameters);
|
||||
walk_parameters(self, parameters);
|
||||
self.exit_node();
|
||||
}
|
||||
|
||||
fn visit_arg(&mut self, arg: &Arg) {
|
||||
self.enter_node(arg);
|
||||
walk_arg(self, arg);
|
||||
fn visit_parameter(&mut self, parameter: &Parameter) {
|
||||
self.enter_node(parameter);
|
||||
walk_parameter(self, parameter);
|
||||
self.exit_node();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user