mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-22 20:45:11 +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
|
@ -2,7 +2,7 @@ use std::borrow::Cow;
|
|||
use std::path::Path;
|
||||
|
||||
use crate::{
|
||||
self as ast, Arguments, Constant, ExceptHandler, Expr, Keyword, MatchCase, Pattern, Ranged,
|
||||
self as ast, Constant, ExceptHandler, Expr, Keyword, MatchCase, Parameters, Pattern, Ranged,
|
||||
Stmt, TypeParam,
|
||||
};
|
||||
use num_traits::Zero;
|
||||
|
@ -347,40 +347,43 @@ where
|
|||
{
|
||||
match stmt {
|
||||
Stmt::FunctionDef(ast::StmtFunctionDef {
|
||||
args,
|
||||
parameters,
|
||||
body,
|
||||
decorator_list,
|
||||
returns,
|
||||
..
|
||||
})
|
||||
| Stmt::AsyncFunctionDef(ast::StmtAsyncFunctionDef {
|
||||
args,
|
||||
parameters,
|
||||
body,
|
||||
decorator_list,
|
||||
returns,
|
||||
..
|
||||
}) => {
|
||||
args.posonlyargs
|
||||
parameters
|
||||
.posonlyargs
|
||||
.iter()
|
||||
.chain(args.args.iter().chain(args.kwonlyargs.iter()))
|
||||
.any(|arg_with_default| {
|
||||
arg_with_default
|
||||
.chain(parameters.args.iter().chain(parameters.kwonlyargs.iter()))
|
||||
.any(|parameter| {
|
||||
parameter
|
||||
.default
|
||||
.as_ref()
|
||||
.is_some_and(|expr| any_over_expr(expr, func))
|
||||
|| arg_with_default
|
||||
|| parameter
|
||||
.def
|
||||
.annotation
|
||||
.as_ref()
|
||||
.is_some_and(|expr| any_over_expr(expr, func))
|
||||
})
|
||||
|| args.vararg.as_ref().is_some_and(|arg| {
|
||||
arg.annotation
|
||||
|| parameters.vararg.as_ref().is_some_and(|parameter| {
|
||||
parameter
|
||||
.annotation
|
||||
.as_ref()
|
||||
.is_some_and(|expr| any_over_expr(expr, func))
|
||||
})
|
||||
|| args.kwarg.as_ref().is_some_and(|arg| {
|
||||
arg.annotation
|
||||
|| parameters.kwarg.as_ref().is_some_and(|parameter| {
|
||||
parameter
|
||||
.annotation
|
||||
.as_ref()
|
||||
.is_some_and(|expr| any_over_expr(expr, func))
|
||||
})
|
||||
|
@ -709,23 +712,23 @@ pub fn extract_handled_exceptions(handlers: &[ExceptHandler]) -> Vec<&Expr> {
|
|||
handled_exceptions
|
||||
}
|
||||
|
||||
/// Returns `true` if the given name is included in the given [`Arguments`].
|
||||
pub fn includes_arg_name(name: &str, arguments: &Arguments) -> bool {
|
||||
if arguments
|
||||
/// Returns `true` if the given name is included in the given [`Parameters`].
|
||||
pub fn includes_arg_name(name: &str, parameters: &Parameters) -> bool {
|
||||
if parameters
|
||||
.posonlyargs
|
||||
.iter()
|
||||
.chain(&arguments.args)
|
||||
.chain(&arguments.kwonlyargs)
|
||||
.chain(¶meters.args)
|
||||
.chain(¶meters.kwonlyargs)
|
||||
.any(|arg| arg.def.arg.as_str() == name)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if let Some(arg) = &arguments.vararg {
|
||||
if let Some(arg) = ¶meters.vararg {
|
||||
if arg.arg.as_str() == name {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if let Some(arg) = &arguments.kwarg {
|
||||
if let Some(arg) = ¶meters.kwarg {
|
||||
if arg.arg.as_str() == name {
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue