Return a slice in StmtClassDef#bases (#6311)

Slices are strictly more flexible, since you can always convert to an
iterator, etc., but not the other way around. Suggested in
https://github.com/astral-sh/ruff/pull/6259#discussion_r1282730994.
This commit is contained in:
Charlie Marsh 2023-08-03 12:21:55 -04:00 committed by GitHub
parent 718e3945e3
commit 2fa508793f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 16 additions and 15 deletions

View file

@ -167,21 +167,19 @@ pub struct StmtClassDef {
impl StmtClassDef {
/// Return an iterator over the bases of the class.
pub fn bases(&self) -> impl Iterator<Item = &Expr> {
self.arguments
.as_ref()
.map(|arguments| &arguments.args)
.into_iter()
.flatten()
pub fn bases(&self) -> &[Expr] {
match &self.arguments {
Some(arguments) => &arguments.args,
None => &[],
}
}
/// Return an iterator over the metaclass keywords of the class.
pub fn keywords(&self) -> impl Iterator<Item = &Keyword> {
self.arguments
.as_ref()
.map(|arguments| &arguments.keywords)
.into_iter()
.flatten()
pub fn keywords(&self) -> &[Keyword] {
match &self.arguments {
Some(arguments) => &arguments.keywords,
None => &[],
}
}
}