mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-27 04:19:18 +00:00
Move includes_arg_name
onto Parameters
(#6282)
## Summary Like #6279, no reason for this to be a standalone method.
This commit is contained in:
parent
fd40864924
commit
23b8fc4366
6 changed files with 40 additions and 40 deletions
|
@ -2080,6 +2080,32 @@ pub struct Parameters {
|
|||
pub kwarg: Option<Box<Parameter>>,
|
||||
}
|
||||
|
||||
impl Parameters {
|
||||
/// Returns `true` if a parameter with the given name included in this [`Parameters`].
|
||||
pub fn includes(&self, name: &str) -> bool {
|
||||
if self
|
||||
.posonlyargs
|
||||
.iter()
|
||||
.chain(&self.args)
|
||||
.chain(&self.kwonlyargs)
|
||||
.any(|arg| arg.parameter.name.as_str() == name)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if let Some(arg) = &self.vararg {
|
||||
if arg.name.as_str() == name {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if let Some(arg) = &self.kwarg {
|
||||
if arg.name.as_str() == name {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
/// An alternative type of AST `arg`. This is used for each function argument that might have a default value.
|
||||
/// Used by `Arguments` original type.
|
||||
///
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue