mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-23 18:43:07 +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
|
@ -51,24 +51,23 @@ pub(super) fn pattern_to_expr(pattern: Pattern) -> Expr {
|
|||
patterns,
|
||||
rest,
|
||||
}) => {
|
||||
let mut keys = keys.into_iter().map(Option::Some).collect::<Vec<_>>();
|
||||
let mut values = patterns
|
||||
let mut items: Vec<ast::DictItem> = keys
|
||||
.into_iter()
|
||||
.map(pattern_to_expr)
|
||||
.collect::<Vec<_>>();
|
||||
.zip(patterns)
|
||||
.map(|(key, pattern)| ast::DictItem {
|
||||
key: Some(key),
|
||||
value: pattern_to_expr(pattern),
|
||||
})
|
||||
.collect();
|
||||
if let Some(rest) = rest {
|
||||
keys.push(None);
|
||||
values.push(Expr::Name(ast::ExprName {
|
||||
let value = Expr::Name(ast::ExprName {
|
||||
range: rest.range,
|
||||
id: rest.id,
|
||||
ctx: ExprContext::Store,
|
||||
}));
|
||||
});
|
||||
items.push(ast::DictItem { key: None, value });
|
||||
}
|
||||
Expr::Dict(ast::ExprDict {
|
||||
range,
|
||||
keys,
|
||||
values,
|
||||
})
|
||||
Expr::Dict(ast::ExprDict { range, items })
|
||||
}
|
||||
Pattern::MatchClass(ast::PatternMatchClass {
|
||||
range,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue