mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-01 14:21:53 +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
|
@ -340,46 +340,46 @@ impl<'a> From<&'a ast::Constant> for ComparableConstant<'a> {
|
|||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Hash)]
|
||||
pub struct ComparableArguments<'a> {
|
||||
posonlyargs: Vec<ComparableArgWithDefault<'a>>,
|
||||
args: Vec<ComparableArgWithDefault<'a>>,
|
||||
vararg: Option<ComparableArg<'a>>,
|
||||
kwonlyargs: Vec<ComparableArgWithDefault<'a>>,
|
||||
kwarg: Option<ComparableArg<'a>>,
|
||||
pub struct ComparableParameters<'a> {
|
||||
posonlyargs: Vec<ComparableParameterWithDefault<'a>>,
|
||||
args: Vec<ComparableParameterWithDefault<'a>>,
|
||||
vararg: Option<ComparableParameter<'a>>,
|
||||
kwonlyargs: Vec<ComparableParameterWithDefault<'a>>,
|
||||
kwarg: Option<ComparableParameter<'a>>,
|
||||
}
|
||||
|
||||
impl<'a> From<&'a ast::Arguments> for ComparableArguments<'a> {
|
||||
fn from(arguments: &'a ast::Arguments) -> Self {
|
||||
impl<'a> From<&'a ast::Parameters> for ComparableParameters<'a> {
|
||||
fn from(parameters: &'a ast::Parameters) -> Self {
|
||||
Self {
|
||||
posonlyargs: arguments.posonlyargs.iter().map(Into::into).collect(),
|
||||
args: arguments.args.iter().map(Into::into).collect(),
|
||||
vararg: arguments.vararg.as_ref().map(Into::into),
|
||||
kwonlyargs: arguments.kwonlyargs.iter().map(Into::into).collect(),
|
||||
kwarg: arguments.kwarg.as_ref().map(Into::into),
|
||||
posonlyargs: parameters.posonlyargs.iter().map(Into::into).collect(),
|
||||
args: parameters.args.iter().map(Into::into).collect(),
|
||||
vararg: parameters.vararg.as_ref().map(Into::into),
|
||||
kwonlyargs: parameters.kwonlyargs.iter().map(Into::into).collect(),
|
||||
kwarg: parameters.kwarg.as_ref().map(Into::into),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<&'a Box<ast::Arguments>> for ComparableArguments<'a> {
|
||||
fn from(arguments: &'a Box<ast::Arguments>) -> Self {
|
||||
(arguments.as_ref()).into()
|
||||
impl<'a> From<&'a Box<ast::Parameters>> for ComparableParameters<'a> {
|
||||
fn from(parameters: &'a Box<ast::Parameters>) -> Self {
|
||||
(parameters.as_ref()).into()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<&'a Box<ast::Arg>> for ComparableArg<'a> {
|
||||
fn from(arg: &'a Box<ast::Arg>) -> Self {
|
||||
impl<'a> From<&'a Box<ast::Parameter>> for ComparableParameter<'a> {
|
||||
fn from(arg: &'a Box<ast::Parameter>) -> Self {
|
||||
(arg.as_ref()).into()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Hash)]
|
||||
pub struct ComparableArg<'a> {
|
||||
pub struct ComparableParameter<'a> {
|
||||
arg: &'a str,
|
||||
annotation: Option<Box<ComparableExpr<'a>>>,
|
||||
}
|
||||
|
||||
impl<'a> From<&'a ast::Arg> for ComparableArg<'a> {
|
||||
fn from(arg: &'a ast::Arg) -> Self {
|
||||
impl<'a> From<&'a ast::Parameter> for ComparableParameter<'a> {
|
||||
fn from(arg: &'a ast::Parameter) -> Self {
|
||||
Self {
|
||||
arg: arg.arg.as_str(),
|
||||
annotation: arg.annotation.as_ref().map(Into::into),
|
||||
|
@ -388,13 +388,13 @@ impl<'a> From<&'a ast::Arg> for ComparableArg<'a> {
|
|||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Hash)]
|
||||
pub struct ComparableArgWithDefault<'a> {
|
||||
def: ComparableArg<'a>,
|
||||
pub struct ComparableParameterWithDefault<'a> {
|
||||
def: ComparableParameter<'a>,
|
||||
default: Option<ComparableExpr<'a>>,
|
||||
}
|
||||
|
||||
impl<'a> From<&'a ast::ArgWithDefault> for ComparableArgWithDefault<'a> {
|
||||
fn from(arg: &'a ast::ArgWithDefault) -> Self {
|
||||
impl<'a> From<&'a ast::ParameterWithDefault> for ComparableParameterWithDefault<'a> {
|
||||
fn from(arg: &'a ast::ParameterWithDefault) -> Self {
|
||||
Self {
|
||||
def: (&arg.def).into(),
|
||||
default: arg.default.as_ref().map(Into::into),
|
||||
|
@ -511,7 +511,7 @@ pub struct ExprUnaryOp<'a> {
|
|||
|
||||
#[derive(Debug, PartialEq, Eq, Hash)]
|
||||
pub struct ExprLambda<'a> {
|
||||
args: ComparableArguments<'a>,
|
||||
parameters: ComparableParameters<'a>,
|
||||
body: Box<ComparableExpr<'a>>,
|
||||
}
|
||||
|
||||
|
@ -739,11 +739,11 @@ impl<'a> From<&'a ast::Expr> for ComparableExpr<'a> {
|
|||
operand: operand.into(),
|
||||
}),
|
||||
ast::Expr::Lambda(ast::ExprLambda {
|
||||
args,
|
||||
parameters,
|
||||
body,
|
||||
range: _range,
|
||||
}) => Self::Lambda(ExprLambda {
|
||||
args: (args.as_ref()).into(),
|
||||
parameters: (parameters.as_ref()).into(),
|
||||
body: body.into(),
|
||||
}),
|
||||
ast::Expr::IfExp(ast::ExprIfExp {
|
||||
|
@ -948,7 +948,7 @@ impl<'a> From<&'a ast::Expr> for ComparableExpr<'a> {
|
|||
#[derive(Debug, PartialEq, Eq, Hash)]
|
||||
pub struct StmtFunctionDef<'a> {
|
||||
name: &'a str,
|
||||
args: ComparableArguments<'a>,
|
||||
parameters: ComparableParameters<'a>,
|
||||
body: Vec<ComparableStmt<'a>>,
|
||||
decorator_list: Vec<ComparableDecorator<'a>>,
|
||||
type_params: Vec<ComparableTypeParam<'a>>,
|
||||
|
@ -958,7 +958,7 @@ pub struct StmtFunctionDef<'a> {
|
|||
#[derive(Debug, PartialEq, Eq, Hash)]
|
||||
pub struct StmtAsyncFunctionDef<'a> {
|
||||
name: &'a str,
|
||||
args: ComparableArguments<'a>,
|
||||
parameters: ComparableParameters<'a>,
|
||||
body: Vec<ComparableStmt<'a>>,
|
||||
decorator_list: Vec<ComparableDecorator<'a>>,
|
||||
type_params: Vec<ComparableTypeParam<'a>>,
|
||||
|
@ -1208,7 +1208,7 @@ impl<'a> From<&'a ast::Stmt> for ComparableStmt<'a> {
|
|||
match stmt {
|
||||
ast::Stmt::FunctionDef(ast::StmtFunctionDef {
|
||||
name,
|
||||
args,
|
||||
parameters,
|
||||
body,
|
||||
decorator_list,
|
||||
returns,
|
||||
|
@ -1216,7 +1216,7 @@ impl<'a> From<&'a ast::Stmt> for ComparableStmt<'a> {
|
|||
range: _range,
|
||||
}) => Self::FunctionDef(StmtFunctionDef {
|
||||
name: name.as_str(),
|
||||
args: args.into(),
|
||||
parameters: parameters.into(),
|
||||
body: body.iter().map(Into::into).collect(),
|
||||
decorator_list: decorator_list.iter().map(Into::into).collect(),
|
||||
returns: returns.as_ref().map(Into::into),
|
||||
|
@ -1224,7 +1224,7 @@ impl<'a> From<&'a ast::Stmt> for ComparableStmt<'a> {
|
|||
}),
|
||||
ast::Stmt::AsyncFunctionDef(ast::StmtAsyncFunctionDef {
|
||||
name,
|
||||
args,
|
||||
parameters,
|
||||
body,
|
||||
decorator_list,
|
||||
returns,
|
||||
|
@ -1232,7 +1232,7 @@ impl<'a> From<&'a ast::Stmt> for ComparableStmt<'a> {
|
|||
range: _range,
|
||||
}) => Self::AsyncFunctionDef(StmtAsyncFunctionDef {
|
||||
name: name.as_str(),
|
||||
args: args.into(),
|
||||
parameters: parameters.into(),
|
||||
body: body.iter().map(Into::into).collect(),
|
||||
decorator_list: decorator_list.iter().map(Into::into).collect(),
|
||||
returns: returns.as_ref().map(Into::into),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue