Add convenience helper methods for AST nodes representing function parameters (#15871)
Some checks are pending
CI / Determine changes (push) Waiting to run
CI / cargo fmt (push) Waiting to run
CI / cargo clippy (push) Blocked by required conditions
CI / cargo test (linux) (push) Blocked by required conditions
CI / cargo test (linux, release) (push) Blocked by required conditions
CI / cargo test (windows) (push) Blocked by required conditions
CI / cargo test (wasm) (push) Blocked by required conditions
CI / cargo build (release) (push) Waiting to run
CI / cargo build (msrv) (push) Blocked by required conditions
CI / cargo fuzz build (push) Blocked by required conditions
CI / fuzz parser (push) Blocked by required conditions
CI / test scripts (push) Blocked by required conditions
CI / ecosystem (push) Blocked by required conditions
CI / cargo shear (push) Blocked by required conditions
CI / python package (push) Waiting to run
CI / pre-commit (push) Waiting to run
CI / mkdocs (push) Waiting to run
CI / formatter instabilities and black similarity (push) Blocked by required conditions
CI / test ruff-lsp (push) Blocked by required conditions
CI / benchmarks (push) Blocked by required conditions

This commit is contained in:
Alex Waygood 2025-02-01 17:16:32 +00:00 committed by GitHub
parent bcdb3f9840
commit d9a1034db0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
36 changed files with 150 additions and 238 deletions

View file

@ -1,6 +1,7 @@
//! Analysis rules for the `typing` module.
use ruff_python_ast::helpers::{any_over_expr, is_const_false, map_subscript};
use ruff_python_ast::identifier::Identifier;
use ruff_python_ast::name::QualifiedName;
use ruff_python_ast::{
self as ast, Expr, ExprCall, Int, Operator, ParameterWithDefault, Parameters, Stmt, StmtAssign,
@ -617,7 +618,7 @@ fn check_type<T: TypeChecker>(binding: &Binding, semantic: &SemanticModel) -> bo
let Some(parameter) = find_parameter(parameters, binding) else {
return false;
};
let Some(ref annotation) = parameter.parameter.annotation else {
let Some(annotation) = parameter.annotation() else {
return false;
};
T::match_annotation(annotation, semantic)
@ -1026,7 +1027,7 @@ fn find_parameter<'a>(
) -> Option<&'a ParameterWithDefault> {
parameters
.iter_non_variadic_params()
.find(|arg| arg.parameter.name.range() == binding.range())
.find(|param| param.identifier() == binding.range())
}
/// Return the [`QualifiedName`] of the value to which the given [`Expr`] is assigned, if any.