Move includes_arg_name onto Parameters (#6282)

## Summary

Like #6279, no reason for this to be a standalone method.
This commit is contained in:
Charlie Marsh 2023-08-02 14:05:26 -04:00 committed by GitHub
parent fd40864924
commit 23b8fc4366
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 40 additions and 40 deletions

View file

@ -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.
///