mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-19 01:51:30 +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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue