mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-10 05:39:12 +00:00
Rename Parameter#arg
and ParameterWithDefault#def
fields (#6255)
## Summary This PR renames... - `Parameter#arg` to `Parameter#name` - `ParameterWithDefault#def` to `ParameterWithDefault#parameter` (such that `ParameterWithDefault` has a `default` and a `parameter`) ## Test Plan `cargo test`
This commit is contained in:
parent
adc8bb7821
commit
9c708d8fc1
56 changed files with 268 additions and 260 deletions
|
@ -381,7 +381,7 @@ pub struct ComparableParameter<'a> {
|
|||
impl<'a> From<&'a ast::Parameter> for ComparableParameter<'a> {
|
||||
fn from(arg: &'a ast::Parameter) -> Self {
|
||||
Self {
|
||||
arg: arg.arg.as_str(),
|
||||
arg: arg.name.as_str(),
|
||||
annotation: arg.annotation.as_ref().map(Into::into),
|
||||
}
|
||||
}
|
||||
|
@ -396,7 +396,7 @@ pub struct ComparableParameterWithDefault<'a> {
|
|||
impl<'a> From<&'a ast::ParameterWithDefault> for ComparableParameterWithDefault<'a> {
|
||||
fn from(arg: &'a ast::ParameterWithDefault) -> Self {
|
||||
Self {
|
||||
def: (&arg.def).into(),
|
||||
def: (&arg.parameter).into(),
|
||||
default: arg.default.as_ref().map(Into::into),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -370,7 +370,7 @@ where
|
|||
.as_ref()
|
||||
.is_some_and(|expr| any_over_expr(expr, func))
|
||||
|| parameter
|
||||
.def
|
||||
.parameter
|
||||
.annotation
|
||||
.as_ref()
|
||||
.is_some_and(|expr| any_over_expr(expr, func))
|
||||
|
@ -719,17 +719,17 @@ pub fn includes_arg_name(name: &str, parameters: &Parameters) -> bool {
|
|||
.iter()
|
||||
.chain(¶meters.args)
|
||||
.chain(¶meters.kwonlyargs)
|
||||
.any(|arg| arg.def.arg.as_str() == name)
|
||||
.any(|arg| arg.parameter.name.as_str() == name)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if let Some(arg) = ¶meters.vararg {
|
||||
if arg.arg.as_str() == name {
|
||||
if arg.name.as_str() == name {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if let Some(arg) = ¶meters.kwarg {
|
||||
if arg.arg.as_str() == name {
|
||||
if arg.name.as_str() == name {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ impl Identifier for Parameter {
|
|||
/// ...
|
||||
/// ```
|
||||
fn identifier(&self) -> TextRange {
|
||||
self.arg.range()
|
||||
self.name.range()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -60,7 +60,7 @@ impl Identifier for ParameterWithDefault {
|
|||
/// ...
|
||||
/// ```
|
||||
fn identifier(&self) -> TextRange {
|
||||
self.def.identifier()
|
||||
self.parameter.identifier()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1826,7 +1826,7 @@ impl From<ExceptHandlerExceptHandler> for ExceptHandler {
|
|||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct Parameter {
|
||||
pub range: TextRange,
|
||||
pub arg: Identifier,
|
||||
pub name: Identifier,
|
||||
pub annotation: Option<Box<Expr>>,
|
||||
}
|
||||
|
||||
|
@ -2069,7 +2069,7 @@ pub struct Parameters {
|
|||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct ParameterWithDefault {
|
||||
pub range: TextRange,
|
||||
pub def: Parameter,
|
||||
pub parameter: Parameter,
|
||||
pub default: Option<Box<Expr>>,
|
||||
}
|
||||
|
||||
|
@ -2113,24 +2113,24 @@ fn clone_boxed_expr(expr: &Box<Expr>) -> Box<Expr> {
|
|||
|
||||
impl ParameterWithDefault {
|
||||
pub fn as_parameter(&self) -> &Parameter {
|
||||
&self.def
|
||||
&self.parameter
|
||||
}
|
||||
|
||||
pub fn to_parameter(&self) -> (Parameter, Option<Box<Expr>>) {
|
||||
let ParameterWithDefault {
|
||||
range: _,
|
||||
def,
|
||||
parameter,
|
||||
default,
|
||||
} = self;
|
||||
(def.clone(), default.as_ref().map(clone_boxed_expr))
|
||||
(parameter.clone(), default.as_ref().map(clone_boxed_expr))
|
||||
}
|
||||
pub fn into_parameter(self) -> (Parameter, Option<Box<Expr>>) {
|
||||
let ParameterWithDefault {
|
||||
range: _,
|
||||
def,
|
||||
parameter,
|
||||
default,
|
||||
} = self;
|
||||
(def, default)
|
||||
(parameter, default)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -664,16 +664,16 @@ pub fn walk_parameters<'a, V: Visitor<'a> + ?Sized>(visitor: &mut V, parameters:
|
|||
}
|
||||
|
||||
for arg in ¶meters.posonlyargs {
|
||||
visitor.visit_parameter(&arg.def);
|
||||
visitor.visit_parameter(&arg.parameter);
|
||||
}
|
||||
for arg in ¶meters.args {
|
||||
visitor.visit_parameter(&arg.def);
|
||||
visitor.visit_parameter(&arg.parameter);
|
||||
}
|
||||
if let Some(arg) = ¶meters.vararg {
|
||||
visitor.visit_parameter(arg);
|
||||
}
|
||||
for arg in ¶meters.kwonlyargs {
|
||||
visitor.visit_parameter(&arg.def);
|
||||
visitor.visit_parameter(&arg.parameter);
|
||||
}
|
||||
if let Some(arg) = ¶meters.kwarg {
|
||||
visitor.visit_parameter(arg);
|
||||
|
|
|
@ -785,7 +785,7 @@ pub fn walk_parameter_with_default<'a, V>(
|
|||
) where
|
||||
V: PreorderVisitor<'a> + ?Sized,
|
||||
{
|
||||
visitor.visit_parameter(¶meter_with_default.def);
|
||||
visitor.visit_parameter(¶meter_with_default.parameter);
|
||||
if let Some(expr) = ¶meter_with_default.default {
|
||||
visitor.visit_expr(expr);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue