mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-18 01:20:40 +00:00
Refactor the ExprDict
node (#11267)
Co-authored-by: Micha Reiser <micha@reiser.io>
This commit is contained in:
parent
de270154a1
commit
6774f27f4b
52 changed files with 2425 additions and 2240 deletions
|
@ -687,10 +687,24 @@ pub struct ExprIf<'a> {
|
|||
orelse: Box<ComparableExpr<'a>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Hash)]
|
||||
pub struct ComparableDictItem<'a> {
|
||||
key: Option<ComparableExpr<'a>>,
|
||||
value: ComparableExpr<'a>,
|
||||
}
|
||||
|
||||
impl<'a> From<&'a ast::DictItem> for ComparableDictItem<'a> {
|
||||
fn from(ast::DictItem { key, value }: &'a ast::DictItem) -> Self {
|
||||
Self {
|
||||
key: key.as_ref().map(ComparableExpr::from),
|
||||
value: value.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Hash)]
|
||||
pub struct ExprDict<'a> {
|
||||
keys: Vec<Option<ComparableExpr<'a>>>,
|
||||
values: Vec<ComparableExpr<'a>>,
|
||||
items: Vec<ComparableDictItem<'a>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Hash)]
|
||||
|
@ -933,16 +947,8 @@ impl<'a> From<&'a ast::Expr> for ComparableExpr<'a> {
|
|||
body: body.into(),
|
||||
orelse: orelse.into(),
|
||||
}),
|
||||
ast::Expr::Dict(ast::ExprDict {
|
||||
keys,
|
||||
values,
|
||||
range: _,
|
||||
}) => Self::Dict(ExprDict {
|
||||
keys: keys
|
||||
.iter()
|
||||
.map(|expr| expr.as_ref().map(Into::into))
|
||||
.collect(),
|
||||
values: values.iter().map(Into::into).collect(),
|
||||
ast::Expr::Dict(ast::ExprDict { items, range: _ }) => Self::Dict(ExprDict {
|
||||
items: items.iter().map(ComparableDictItem::from).collect(),
|
||||
}),
|
||||
ast::Expr::Set(ast::ExprSet { elts, range: _ }) => Self::Set(ExprSet {
|
||||
elts: elts.iter().map(Into::into).collect(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue