mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-27 12:29:28 +00:00
Improve counting of message arguments when msg is provided as a keyword (#6456)
Closes https://github.com/astral-sh/ruff/issues/6454.
This commit is contained in:
parent
3ecd263b4d
commit
395bb31247
4 changed files with 20 additions and 14 deletions
|
@ -2126,23 +2126,21 @@ impl Arguments {
|
|||
})
|
||||
}
|
||||
|
||||
/// Return the positional argument at the given index, or `None` if no such argument exists.
|
||||
pub fn find_positional(&self, position: usize) -> Option<&Expr> {
|
||||
self.args
|
||||
.iter()
|
||||
.take_while(|expr| !expr.is_starred_expr())
|
||||
.nth(position)
|
||||
}
|
||||
|
||||
/// Return the argument with the given name or at the given position, or `None` if no such
|
||||
/// argument exists. Used to retrieve arguments that can be provided _either_ as keyword or
|
||||
/// positional arguments.
|
||||
pub fn find_argument(&self, name: &str, position: usize) -> Option<&Expr> {
|
||||
self.keywords
|
||||
.iter()
|
||||
.find(|keyword| {
|
||||
let Keyword { arg, .. } = keyword;
|
||||
arg.as_ref().is_some_and(|arg| arg == name)
|
||||
})
|
||||
self.find_keyword(name)
|
||||
.map(|keyword| &keyword.value)
|
||||
.or_else(|| {
|
||||
self.args
|
||||
.iter()
|
||||
.take_while(|expr| !expr.is_starred_expr())
|
||||
.nth(position)
|
||||
})
|
||||
.or_else(|| self.find_positional(position))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue