mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 18:28:24 +00:00
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:
parent
718e3945e3
commit
2fa508793f
6 changed files with 16 additions and 15 deletions
|
@ -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 => &[],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue