simplify decorator arguments in the AST

they are always strings so just return Str. We can switch back to Expr in the future, if we need it.
This commit is contained in:
PgBiel 2024-06-27 18:27:45 -03:00
parent 181c633fe5
commit 866c5364a0
2 changed files with 4 additions and 18 deletions

View File

@ -108,20 +108,9 @@ impl<'a> Decorator<'a> {
} }
/// The decorator's arguments. /// The decorator's arguments.
pub fn arguments(self) -> impl DoubleEndedIterator<Item = Expr<'a>> { /// Currently, they are always strings.
let mut found_non_ident = false; pub fn arguments(self) -> impl DoubleEndedIterator<Item = Str<'a>> {
self.0 self.0.children().filter_map(Str::from_untyped)
.children()
.filter(move |node| {
// Skip the name (first identifier).
if node.is::<Ident>() {
return found_non_ident;
} else if !node.kind().is_trivia() {
found_non_ident = true;
}
true
})
.filter_map(Expr::from_untyped)
} }
} }

View File

@ -374,10 +374,7 @@ fn check_decorator_suppresses_warning(
} }
for argument in decorator.arguments() { for argument in decorator.arguments() {
let ast::Expr::Str(str) = argument else { if warning.name() == argument.get() {
continue;
};
if warning.name() == str.get() {
return true; return true;
} }
} }