diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/lambda_assignment.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/lambda_assignment.rs index 776b2e8842..e48ff57b3a 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/lambda_assignment.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/lambda_assignment.rs @@ -196,9 +196,7 @@ fn function( value: Some(Box::new(body.clone())), range: TextRange::default(), }); - let parameters = parameters - .cloned() - .unwrap_or_else(|| Parameters::empty(TextRange::default())); + let parameters = parameters.cloned().unwrap_or_default(); if let Some(annotation) = annotation { if let Some((arg_types, return_type)) = extract_types(annotation, semantic) { // A `lambda` expression can only have positional and positional-only diff --git a/crates/ruff_linter/src/rules/pylint/rules/no_self_use.rs b/crates/ruff_linter/src/rules/pylint/rules/no_self_use.rs index 65291246ff..a642334774 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/no_self_use.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/no_self_use.rs @@ -1,8 +1,8 @@ use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; +use ruff_python_ast as ast; use ruff_python_ast::identifier::Identifier; use ruff_python_ast::name::QualifiedName; -use ruff_python_ast::{self as ast, ParameterWithDefault}; use ruff_python_semantic::{ analyze::{function_type, visibility}, Scope, ScopeId, ScopeKind, @@ -102,9 +102,8 @@ pub(crate) fn no_self_use( .posonlyargs .iter() .chain(¶meters.args) - .chain(¶meters.kwonlyargs) .next() - .map(ParameterWithDefault::as_parameter) + .map(|param| ¶m.parameter) else { return; }; diff --git a/crates/ruff_python_ast/src/nodes.rs b/crates/ruff_python_ast/src/nodes.rs index 8f8c334ccc..e4323ec952 100644 --- a/crates/ruff_python_ast/src/nodes.rs +++ b/crates/ruff_python_ast/src/nodes.rs @@ -3183,7 +3183,7 @@ pub struct Decorator { /// /// NOTE: This type differs from the original Python AST. See: [arguments](https://docs.python.org/3/library/ast.html#ast.arguments). -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Default)] pub struct Parameters { pub range: TextRange, pub posonlyargs: Vec, @@ -3408,48 +3408,6 @@ impl Deref for TypeParams { pub type Suite = Vec; -impl Parameters { - pub fn empty(range: TextRange) -> Self { - Self { - range, - posonlyargs: Vec::new(), - args: Vec::new(), - vararg: None, - kwonlyargs: Vec::new(), - kwarg: None, - } - } -} - -impl ParameterWithDefault { - pub fn as_parameter(&self) -> &Parameter { - &self.parameter - } -} - -impl Parameters { - pub fn defaults(&self) -> impl std::iter::Iterator { - self.posonlyargs - .iter() - .chain(self.args.iter()) - .filter_map(|arg| arg.default.as_ref().map(std::convert::AsRef::as_ref)) - } - - #[allow(clippy::type_complexity)] - pub fn split_kwonlyargs(&self) -> (Vec<&Parameter>, Vec<(&Parameter, &Expr)>) { - let mut args = Vec::new(); - let mut with_defaults = Vec::new(); - for arg in &self.kwonlyargs { - if let Some(ref default) = arg.default { - with_defaults.push((arg.as_parameter(), &**default)); - } else { - args.push(arg.as_parameter()); - } - } - (args, with_defaults) - } -} - /// The kind of escape command as defined in [IPython Syntax] in the IPython codebase. /// /// [IPython Syntax]: https://github.com/ipython/ipython/blob/635815e8f1ded5b764d66cacc80bbe25e9e2587f/IPython/core/inputtransformer2.py#L335-L343 diff --git a/crates/ruff_python_parser/src/parser/statement.rs b/crates/ruff_python_parser/src/parser/statement.rs index 651af372e8..b7816ea6e7 100644 --- a/crates/ruff_python_parser/src/parser/statement.rs +++ b/crates/ruff_python_parser/src/parser/statement.rs @@ -6,7 +6,7 @@ use rustc_hash::FxHashSet; use ruff_python_ast::{ self as ast, ExceptHandler, Expr, ExprContext, IpyEscapeKind, Operator, Stmt, WithItem, }; -use ruff_text_size::{Ranged, TextRange, TextSize}; +use ruff_text_size::{Ranged, TextSize}; use crate::parser::expression::{GeneratorExpressionInParentheses, ParsedExpr, EXPR_SET}; use crate::parser::progress::ParserProgress; @@ -2861,7 +2861,7 @@ impl<'src> Parser<'src> { // the parser will drop the previous ones. Another thing is the vararg and kwarg // uses `Parameter` (not `ParameterWithDefault`) which means that the parser cannot // recover well from `*args=(1, 2)`. - let mut parameters = ast::Parameters::empty(TextRange::default()); + let mut parameters = ast::Parameters::default(); let mut seen_default_param = false; // `a=10` let mut seen_positional_only_separator = false; // `/`