mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 21:05:08 +00: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:
parent
a82eb9544c
commit
adc8bb7821
102 changed files with 2585 additions and 2529 deletions
|
@ -1,8 +1,8 @@
|
|||
use std::cmp::Ordering;
|
||||
|
||||
use ruff_python_ast::{
|
||||
self as ast, Arguments, Comprehension, Expr, ExprAttribute, ExprBinOp, ExprIfExp, ExprSlice,
|
||||
ExprStarred, MatchCase, Ranged,
|
||||
self as ast, Comprehension, Expr, ExprAttribute, ExprBinOp, ExprIfExp, ExprSlice, ExprStarred,
|
||||
MatchCase, Parameters, Ranged,
|
||||
};
|
||||
use ruff_text_size::TextRange;
|
||||
|
||||
|
@ -15,7 +15,7 @@ use ruff_source_file::{Locator, UniversalNewlines};
|
|||
|
||||
use crate::comments::visitor::{CommentPlacement, DecoratedComment};
|
||||
use crate::expression::expr_slice::{assign_comment_in_slice, ExprSliceCommentSection};
|
||||
use crate::other::arguments::{
|
||||
use crate::other::parameters::{
|
||||
assign_argument_separator_comment_placement, find_argument_separators,
|
||||
};
|
||||
|
||||
|
@ -44,8 +44,8 @@ pub(super) fn place_comment<'a>(
|
|||
// Change comment placement depending on the node type. These can be seen as node-specific
|
||||
// fixups.
|
||||
match comment.enclosing_node() {
|
||||
AnyNodeRef::Arguments(arguments) => {
|
||||
handle_arguments_separator_comment(comment, arguments, locator)
|
||||
AnyNodeRef::Parameters(arguments) => {
|
||||
handle_parameters_separator_comment(comment, arguments, locator)
|
||||
}
|
||||
AnyNodeRef::Comprehension(comprehension) => {
|
||||
handle_comprehension_comment(comment, comprehension, locator)
|
||||
|
@ -559,16 +559,16 @@ fn handle_own_line_comment_after_branch<'a>(
|
|||
}
|
||||
}
|
||||
|
||||
/// Attaches comments for the positional only arguments separator `/` or the keywords only arguments
|
||||
/// separator `*` as dangling comments to the enclosing [`Arguments`] node.
|
||||
/// Attaches comments for the positional-only parameters separator `/` or the keywords-only
|
||||
/// parameters separator `*` as dangling comments to the enclosing [`Parameters`] node.
|
||||
///
|
||||
/// See [`assign_argument_separator_comment_placement`]
|
||||
fn handle_arguments_separator_comment<'a>(
|
||||
fn handle_parameters_separator_comment<'a>(
|
||||
comment: DecoratedComment<'a>,
|
||||
arguments: &Arguments,
|
||||
parameters: &Parameters,
|
||||
locator: &Locator,
|
||||
) -> CommentPlacement<'a> {
|
||||
let (slash, star) = find_argument_separators(locator.contents(), arguments);
|
||||
let (slash, star) = find_argument_separators(locator.contents(), parameters);
|
||||
let comment_range = comment.slice().range();
|
||||
let placement = assign_argument_separator_comment_placement(
|
||||
slash.as_ref(),
|
||||
|
@ -832,11 +832,11 @@ fn handle_leading_function_with_decorators_comment(comment: DecoratedComment) ->
|
|||
.preceding_node()
|
||||
.is_some_and(|node| node.is_decorator());
|
||||
|
||||
let is_following_arguments = comment
|
||||
let is_following_parameters = comment
|
||||
.following_node()
|
||||
.is_some_and(|node| node.is_arguments());
|
||||
.is_some_and(|node| node.is_parameters());
|
||||
|
||||
if comment.line_position().is_own_line() && is_preceding_decorator && is_following_arguments {
|
||||
if comment.line_position().is_own_line() && is_preceding_decorator && is_following_parameters {
|
||||
CommentPlacement::dangling(comment.enclosing_node(), comment)
|
||||
} else {
|
||||
CommentPlacement::Default(comment)
|
||||
|
|
|
@ -4,7 +4,7 @@ expression: comments.debug(test_case.source_code)
|
|||
---
|
||||
{
|
||||
Node {
|
||||
kind: Arguments,
|
||||
kind: Parameters,
|
||||
range: 9..39,
|
||||
source: `(⏎`,
|
||||
}: {
|
||||
|
|
|
@ -4,7 +4,7 @@ expression: comments.debug(test_case.source_code)
|
|||
---
|
||||
{
|
||||
Node {
|
||||
kind: Arguments,
|
||||
kind: Parameters,
|
||||
range: 9..96,
|
||||
source: `(a=10,/, # trailing positio...t comment.⏎`,
|
||||
}: {
|
||||
|
@ -19,7 +19,7 @@ expression: comments.debug(test_case.source_code)
|
|||
"trailing": [],
|
||||
},
|
||||
Node {
|
||||
kind: ArgWithDefault,
|
||||
kind: ParameterWithDefault,
|
||||
range: 90..94,
|
||||
source: `b=20`,
|
||||
}: {
|
||||
|
|
|
@ -4,7 +4,7 @@ expression: comments.debug(test_case.source_code)
|
|||
---
|
||||
{
|
||||
Node {
|
||||
kind: Arguments,
|
||||
kind: Parameters,
|
||||
range: 9..179,
|
||||
source: `(⏎`,
|
||||
}: {
|
||||
|
@ -24,7 +24,7 @@ expression: comments.debug(test_case.source_code)
|
|||
"trailing": [],
|
||||
},
|
||||
Node {
|
||||
kind: ArgWithDefault,
|
||||
kind: ParameterWithDefault,
|
||||
range: 15..19,
|
||||
source: `a=10`,
|
||||
}: {
|
||||
|
@ -39,7 +39,7 @@ expression: comments.debug(test_case.source_code)
|
|||
],
|
||||
},
|
||||
Node {
|
||||
kind: ArgWithDefault,
|
||||
kind: ParameterWithDefault,
|
||||
range: 173..177,
|
||||
source: `b=20`,
|
||||
}: {
|
||||
|
|
|
@ -4,7 +4,7 @@ expression: comments.debug(test_case.source_code)
|
|||
---
|
||||
{
|
||||
Node {
|
||||
kind: Arguments,
|
||||
kind: Parameters,
|
||||
range: 9..170,
|
||||
source: `(⏎`,
|
||||
}: {
|
||||
|
@ -24,7 +24,7 @@ expression: comments.debug(test_case.source_code)
|
|||
"trailing": [],
|
||||
},
|
||||
Node {
|
||||
kind: ArgWithDefault,
|
||||
kind: ParameterWithDefault,
|
||||
range: 15..16,
|
||||
source: `a`,
|
||||
}: {
|
||||
|
@ -39,7 +39,7 @@ expression: comments.debug(test_case.source_code)
|
|||
],
|
||||
},
|
||||
Node {
|
||||
kind: ArgWithDefault,
|
||||
kind: ParameterWithDefault,
|
||||
range: 166..167,
|
||||
source: `b`,
|
||||
}: {
|
||||
|
|
|
@ -4,7 +4,7 @@ expression: comments.debug(test_case.source_code)
|
|||
---
|
||||
{
|
||||
Node {
|
||||
kind: Arguments,
|
||||
kind: Parameters,
|
||||
range: 9..166,
|
||||
source: `(⏎`,
|
||||
}: {
|
||||
|
@ -24,7 +24,7 @@ expression: comments.debug(test_case.source_code)
|
|||
"trailing": [],
|
||||
},
|
||||
Node {
|
||||
kind: ArgWithDefault,
|
||||
kind: ParameterWithDefault,
|
||||
range: 15..16,
|
||||
source: `a`,
|
||||
}: {
|
||||
|
|
|
@ -4,7 +4,7 @@ expression: comments.debug(test_case.source_code)
|
|||
---
|
||||
{
|
||||
Node {
|
||||
kind: Arguments,
|
||||
kind: Parameters,
|
||||
range: 9..170,
|
||||
source: `(⏎`,
|
||||
}: {
|
||||
|
@ -24,7 +24,7 @@ expression: comments.debug(test_case.source_code)
|
|||
"trailing": [],
|
||||
},
|
||||
Node {
|
||||
kind: ArgWithDefault,
|
||||
kind: ParameterWithDefault,
|
||||
range: 15..16,
|
||||
source: `a`,
|
||||
}: {
|
||||
|
@ -39,7 +39,7 @@ expression: comments.debug(test_case.source_code)
|
|||
],
|
||||
},
|
||||
Node {
|
||||
kind: ArgWithDefault,
|
||||
kind: ParameterWithDefault,
|
||||
range: 166..167,
|
||||
source: `b`,
|
||||
}: {
|
||||
|
|
|
@ -4,7 +4,7 @@ expression: comments.debug(test_case.source_code)
|
|||
---
|
||||
{
|
||||
Node {
|
||||
kind: ArgWithDefault,
|
||||
kind: ParameterWithDefault,
|
||||
range: 15..16,
|
||||
source: `a`,
|
||||
}: {
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use std::iter::Peekable;
|
||||
|
||||
use ruff_python_ast::{
|
||||
Alias, Arg, ArgWithDefault, Arguments, Comprehension, Decorator, ElifElseClause, ExceptHandler,
|
||||
Expr, Keyword, MatchCase, Mod, Pattern, Ranged, Stmt, TypeParam, WithItem,
|
||||
Alias, Comprehension, Decorator, ElifElseClause, ExceptHandler, Expr, Keyword, MatchCase, Mod,
|
||||
Parameter, ParameterWithDefault, Parameters, Pattern, Ranged, Stmt, TypeParam, WithItem,
|
||||
};
|
||||
use ruff_text_size::{TextRange, TextSize};
|
||||
|
||||
|
@ -229,25 +229,25 @@ impl<'ast> PreorderVisitor<'ast> for CommentsVisitor<'ast> {
|
|||
self.finish_node(format_spec);
|
||||
}
|
||||
|
||||
fn visit_arguments(&mut self, arguments: &'ast Arguments) {
|
||||
if self.start_node(arguments).is_traverse() {
|
||||
walk_arguments(self, arguments);
|
||||
fn visit_parameters(&mut self, parameters: &'ast Parameters) {
|
||||
if self.start_node(parameters).is_traverse() {
|
||||
walk_parameters(self, parameters);
|
||||
}
|
||||
self.finish_node(arguments);
|
||||
self.finish_node(parameters);
|
||||
}
|
||||
|
||||
fn visit_arg(&mut self, arg: &'ast Arg) {
|
||||
fn visit_parameter(&mut self, arg: &'ast Parameter) {
|
||||
if self.start_node(arg).is_traverse() {
|
||||
walk_arg(self, arg);
|
||||
walk_parameter(self, arg);
|
||||
}
|
||||
self.finish_node(arg);
|
||||
}
|
||||
|
||||
fn visit_arg_with_default(&mut self, arg_with_default: &'ast ArgWithDefault) {
|
||||
if self.start_node(arg_with_default).is_traverse() {
|
||||
walk_arg_with_default(self, arg_with_default);
|
||||
fn visit_parameter_with_default(&mut self, parameter_with_default: &'ast ParameterWithDefault) {
|
||||
if self.start_node(parameter_with_default).is_traverse() {
|
||||
walk_parameter_with_default(self, parameter_with_default);
|
||||
}
|
||||
self.finish_node(arg_with_default);
|
||||
self.finish_node(parameter_with_default);
|
||||
}
|
||||
|
||||
fn visit_keyword(&mut self, keyword: &'ast Keyword) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue