mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-17 09:00:26 +00:00
Implement iter()
, len()
and is_empty()
for all display-literal AST nodes (#12807)
This commit is contained in:
parent
a99a45868c
commit
aa0db338d9
56 changed files with 304 additions and 240 deletions
|
@ -856,6 +856,27 @@ impl ExprDict {
|
|||
pub fn value(&self, n: usize) -> &Expr {
|
||||
self.items[n].value()
|
||||
}
|
||||
|
||||
pub fn iter(&self) -> std::slice::Iter<'_, DictItem> {
|
||||
self.items.iter()
|
||||
}
|
||||
|
||||
pub fn len(&self) -> usize {
|
||||
self.items.len()
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.items.is_empty()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> IntoIterator for &'a ExprDict {
|
||||
type IntoIter = std::slice::Iter<'a, DictItem>;
|
||||
type Item = &'a DictItem;
|
||||
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
self.iter()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ExprDict> for Expr {
|
||||
|
@ -955,6 +976,29 @@ pub struct ExprSet {
|
|||
pub elts: Vec<Expr>,
|
||||
}
|
||||
|
||||
impl ExprSet {
|
||||
pub fn iter(&self) -> std::slice::Iter<'_, Expr> {
|
||||
self.elts.iter()
|
||||
}
|
||||
|
||||
pub fn len(&self) -> usize {
|
||||
self.elts.len()
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.elts.is_empty()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> IntoIterator for &'a ExprSet {
|
||||
type IntoIter = std::slice::Iter<'a, Expr>;
|
||||
type Item = &'a Expr;
|
||||
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
self.iter()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ExprSet> for Expr {
|
||||
fn from(payload: ExprSet) -> Self {
|
||||
Expr::Set(payload)
|
||||
|
@ -2759,6 +2803,29 @@ pub struct ExprList {
|
|||
pub ctx: ExprContext,
|
||||
}
|
||||
|
||||
impl ExprList {
|
||||
pub fn iter(&self) -> std::slice::Iter<'_, Expr> {
|
||||
self.elts.iter()
|
||||
}
|
||||
|
||||
pub fn len(&self) -> usize {
|
||||
self.elts.len()
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.elts.is_empty()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> IntoIterator for &'a ExprList {
|
||||
type IntoIter = std::slice::Iter<'a, Expr>;
|
||||
type Item = &'a Expr;
|
||||
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
self.iter()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ExprList> for Expr {
|
||||
fn from(payload: ExprList) -> Self {
|
||||
Expr::List(payload)
|
||||
|
@ -2776,6 +2843,29 @@ pub struct ExprTuple {
|
|||
pub parenthesized: bool,
|
||||
}
|
||||
|
||||
impl ExprTuple {
|
||||
pub fn iter(&self) -> std::slice::Iter<'_, Expr> {
|
||||
self.elts.iter()
|
||||
}
|
||||
|
||||
pub fn len(&self) -> usize {
|
||||
self.elts.len()
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.elts.is_empty()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> IntoIterator for &'a ExprTuple {
|
||||
type IntoIter = std::slice::Iter<'a, Expr>;
|
||||
type Item = &'a Expr;
|
||||
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
self.iter()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ExprTuple> for Expr {
|
||||
fn from(payload: ExprTuple) -> Self {
|
||||
Expr::Tuple(payload)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue