diff --git a/crates/ruff_linter/src/checkers/ast/mod.rs b/crates/ruff_linter/src/checkers/ast/mod.rs index 566924b532..259eda1bde 100644 --- a/crates/ruff_linter/src/checkers/ast/mod.rs +++ b/crates/ruff_linter/src/checkers/ast/mod.rs @@ -1172,8 +1172,8 @@ impl<'a> Visitor<'a> for Checker<'a> { let Keyword { arg, value, .. } = keyword; match (arg.as_ref(), value) { // Ex) NamedTuple("a", **{"a": int}) - (None, Expr::Dict(ast::ExprDict { keys, values, .. })) => { - for (key, value) in keys.iter().zip(values) { + (None, Expr::Dict(ast::ExprDict { items, .. })) => { + for ast::DictItem { key, value } in items { if let Some(key) = key.as_ref() { self.visit_non_type_definition(key); self.visit_type_definition(value); @@ -1200,16 +1200,11 @@ impl<'a> Visitor<'a> for Checker<'a> { self.visit_non_type_definition(arg); } for arg in args { - if let Expr::Dict(ast::ExprDict { - keys, - values, - range: _, - }) = arg - { - for key in keys.iter().flatten() { - self.visit_non_type_definition(key); - } - for value in values { + if let Expr::Dict(ast::ExprDict { items, range: _ }) = arg { + for ast::DictItem { key, value } in items { + if let Some(key) = key { + self.visit_non_type_definition(key); + } self.visit_type_definition(value); } } else { diff --git a/crates/ruff_linter/src/rules/flake8_bandit/rules/django_extra.rs b/crates/ruff_linter/src/rules/flake8_bandit/rules/django_extra.rs index 34ceaf9070..258b2381fa 100644 --- a/crates/ruff_linter/src/rules/flake8_bandit/rules/django_extra.rs +++ b/crates/ruff_linter/src/rules/flake8_bandit/rules/django_extra.rs @@ -54,11 +54,12 @@ fn is_call_insecure(call: &ast::ExprCall) -> bool { if let Some(argument) = call.arguments.find_argument(argument_name, position) { match argument_name { "select" => match argument { - Expr::Dict(ExprDict { keys, values, .. }) => { - if !keys.iter().flatten().all(Expr::is_string_literal_expr) { - return true; - } - if !values.iter().all(Expr::is_string_literal_expr) { + Expr::Dict(ExprDict { items, .. }) => { + if items.iter().any(|ast::DictItem { key, value }| { + key.as_ref() + .is_some_and(|key| !key.is_string_literal_expr()) + || !value.is_string_literal_expr() + }) { return true; } } diff --git a/crates/ruff_linter/src/rules/flake8_logging_format/rules/logging_call.rs b/crates/ruff_linter/src/rules/flake8_logging_format/rules/logging_call.rs index 2f6801f9f9..9b7c4ac0e8 100644 --- a/crates/ruff_linter/src/rules/flake8_logging_format/rules/logging_call.rs +++ b/crates/ruff_linter/src/rules/flake8_logging_format/rules/logging_call.rs @@ -89,18 +89,19 @@ fn check_msg(checker: &mut Checker, msg: &Expr) { /// Check contents of the `extra` argument to logging calls. fn check_log_record_attr_clash(checker: &mut Checker, extra: &Keyword) { match &extra.value { - Expr::Dict(ast::ExprDict { keys, .. }) => { - for key in keys { - if let Some(key) = &key { - if let Expr::StringLiteral(ast::ExprStringLiteral { value: attr, .. }) = key { - if is_reserved_attr(attr.to_str()) { - checker.diagnostics.push(Diagnostic::new( - LoggingExtraAttrClash(attr.to_string()), - key.range(), - )); - } - } + Expr::Dict(dict) => { + for invalid_key in dict.iter_keys().filter_map(|key| { + let string_key = key?.as_string_literal_expr()?; + if is_reserved_attr(string_key.value.to_str()) { + Some(string_key) + } else { + None } + }) { + checker.diagnostics.push(Diagnostic::new( + LoggingExtraAttrClash(invalid_key.value.to_string()), + invalid_key.range(), + )); } } Expr::Call(ast::ExprCall { diff --git a/crates/ruff_linter/src/rules/flake8_pie/rules/reimplemented_container_builtin.rs b/crates/ruff_linter/src/rules/flake8_pie/rules/reimplemented_container_builtin.rs index 9c35184645..730bb84158 100644 --- a/crates/ruff_linter/src/rules/flake8_pie/rules/reimplemented_container_builtin.rs +++ b/crates/ruff_linter/src/rules/flake8_pie/rules/reimplemented_container_builtin.rs @@ -71,7 +71,7 @@ pub(crate) fn reimplemented_container_builtin(checker: &mut Checker, expr: &Expr let container = match &**body { Expr::List(ast::ExprList { elts, .. }) if elts.is_empty() => Container::List, - Expr::Dict(ast::ExprDict { values, .. }) if values.is_empty() => Container::Dict, + Expr::Dict(ast::ExprDict { items, .. }) if items.is_empty() => Container::Dict, _ => return, }; let mut diagnostic = Diagnostic::new(ReimplementedContainerBuiltin { container }, expr.range()); diff --git a/crates/ruff_linter/src/rules/flake8_pie/rules/unnecessary_dict_kwargs.rs b/crates/ruff_linter/src/rules/flake8_pie/rules/unnecessary_dict_kwargs.rs index 0d462c1748..81f34b0b18 100644 --- a/crates/ruff_linter/src/rules/flake8_pie/rules/unnecessary_dict_kwargs.rs +++ b/crates/ruff_linter/src/rules/flake8_pie/rules/unnecessary_dict_kwargs.rs @@ -65,36 +65,36 @@ pub(crate) fn unnecessary_dict_kwargs(checker: &mut Checker, call: &ast::ExprCal continue; } - let Expr::Dict(ast::ExprDict { keys, values, .. }) = &keyword.value else { + let Expr::Dict(dict) = &keyword.value else { continue; }; // Ex) `foo(**{**bar})` - if matches!(keys.as_slice(), [None]) { - let mut diagnostic = Diagnostic::new(UnnecessaryDictKwargs, keyword.range()); - - diagnostic.set_fix(Fix::safe_edit(Edit::range_replacement( - format!("**{}", checker.locator().slice(values[0].range())), + if let [ast::DictItem { key: None, value }] = dict.items.as_slice() { + let diagnostic = Diagnostic::new(UnnecessaryDictKwargs, keyword.range()); + let edit = Edit::range_replacement( + format!("**{}", checker.locator().slice(value)), keyword.range(), - ))); - - checker.diagnostics.push(diagnostic); + ); + checker + .diagnostics + .push(diagnostic.with_fix(Fix::safe_edit(edit))); continue; } // Ensure that every keyword is a valid keyword argument (e.g., avoid errors for cases like // `foo(**{"bar-bar": 1})`). - let kwargs = keys - .iter() - .filter_map(|key| key.as_ref().and_then(as_kwarg)) - .collect::>(); - if kwargs.len() != keys.len() { + let kwargs: Vec<&str> = dict + .iter_keys() + .filter_map(|key| key.and_then(as_kwarg)) + .collect(); + if kwargs.len() != dict.items.len() { continue; } let mut diagnostic = Diagnostic::new(UnnecessaryDictKwargs, keyword.range()); - if values.is_empty() { + if dict.items.is_empty() { diagnostic.try_set_fix(|| { remove_argument( keyword, @@ -119,7 +119,7 @@ pub(crate) fn unnecessary_dict_kwargs(checker: &mut Checker, call: &ast::ExprCal diagnostic.set_fix(Fix::safe_edit(Edit::range_replacement( kwargs .iter() - .zip(values.iter()) + .zip(dict.iter_values()) .map(|(kwarg, value)| { format!("{}={}", kwarg, checker.locator().slice(value.range())) }) @@ -150,9 +150,9 @@ fn duplicates(call: &ast::ExprCall) -> FxHashSet<&str> { if !seen.insert(name.as_str()) { duplicates.insert(name.as_str()); } - } else if let Expr::Dict(ast::ExprDict { keys, .. }) = &keyword.value { - for key in keys { - if let Some(name) = key.as_ref().and_then(as_kwarg) { + } else if let Expr::Dict(dict) = &keyword.value { + for key in dict.iter_keys() { + if let Some(name) = key.and_then(as_kwarg) { if !seen.insert(name) { duplicates.insert(name); } diff --git a/crates/ruff_linter/src/rules/flake8_pie/rules/unnecessary_spread.rs b/crates/ruff_linter/src/rules/flake8_pie/rules/unnecessary_spread.rs index aa81145bd8..0fd2a96c5f 100644 --- a/crates/ruff_linter/src/rules/flake8_pie/rules/unnecessary_spread.rs +++ b/crates/ruff_linter/src/rules/flake8_pie/rules/unnecessary_spread.rs @@ -49,8 +49,8 @@ impl Violation for UnnecessarySpread { pub(crate) fn unnecessary_spread(checker: &mut Checker, dict: &ast::ExprDict) { // The first "end" is the start of the dictionary, immediately following the open bracket. let mut prev_end = dict.start() + TextSize::from(1); - for item in dict.keys.iter().zip(dict.values.iter()) { - if let (None, value) = item { + for ast::DictItem { key, value } in &dict.items { + if key.is_none() { // We only care about when the key is None which indicates a spread `**` // inside a dict. if let Expr::Dict(inner) = value { @@ -61,7 +61,7 @@ pub(crate) fn unnecessary_spread(checker: &mut Checker, dict: &ast::ExprDict) { checker.diagnostics.push(diagnostic); } } - prev_end = item.1.end(); + prev_end = value.end(); } } @@ -75,7 +75,7 @@ fn unnecessary_spread_fix( let doublestar = SimpleTokenizer::starts_at(prev_end, locator.contents()) .find(|tok| matches!(tok.kind(), SimpleTokenKind::DoubleStar))?; - if let Some(last) = dict.values.last() { + if let Some(last) = dict.iter_values().last() { // Ex) `**{a: 1, b: 2}` let mut edits = vec![]; for tok in SimpleTokenizer::starts_at(last.end(), locator.contents()).skip_trivia() { diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/simple_defaults.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/simple_defaults.rs index 65bd78fad1..2d66fc868d 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/simple_defaults.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/simple_defaults.rs @@ -298,17 +298,13 @@ fn is_valid_default_value_with_annotation( .iter() .all(|e| is_valid_default_value_with_annotation(e, false, locator, semantic)); } - Expr::Dict(ast::ExprDict { - keys, - values, - range: _, - }) => { + Expr::Dict(ast::ExprDict { items, range: _ }) => { return allow_container - && keys.len() <= 10 - && keys.iter().zip(values).all(|(k, v)| { - k.as_ref().is_some_and(|k| { - is_valid_default_value_with_annotation(k, false, locator, semantic) - }) && is_valid_default_value_with_annotation(v, false, locator, semantic) + && items.len() <= 10 + && items.iter().all(|ast::DictItem { key, value }| { + key.as_ref().is_some_and(|key| { + is_valid_default_value_with_annotation(key, false, locator, semantic) + }) && is_valid_default_value_with_annotation(value, false, locator, semantic) }); } Expr::UnaryOp(ast::ExprUnaryOp { diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/yoda_conditions.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/yoda_conditions.rs index 1dfbeb3559..f8f88b1e05 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/yoda_conditions.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/yoda_conditions.rs @@ -113,8 +113,8 @@ impl ConstantLikelihood { .map(|expr| ConstantLikelihood::from_expression(expr, preview)) .min() .unwrap_or(ConstantLikelihood::Definitely), - Expr::Dict(ast::ExprDict { values: vs, .. }) if preview.is_enabled() => { - if vs.is_empty() { + Expr::Dict(ast::ExprDict { items, .. }) if preview.is_enabled() => { + if items.is_empty() { ConstantLikelihood::Definitely } else { ConstantLikelihood::Probably diff --git a/crates/ruff_linter/src/rules/pyflakes/rules/repeated_keys.rs b/crates/ruff_linter/src/rules/pyflakes/rules/repeated_keys.rs index 963ddd7392..5575e15410 100644 --- a/crates/ruff_linter/src/rules/pyflakes/rules/repeated_keys.rs +++ b/crates/ruff_linter/src/rules/pyflakes/rules/repeated_keys.rs @@ -132,10 +132,10 @@ impl Violation for MultiValueRepeatedKeyVariable { pub(crate) fn repeated_keys(checker: &mut Checker, dict: &ast::ExprDict) { // Generate a map from key to (index, value). let mut seen: FxHashMap> = - FxHashMap::with_capacity_and_hasher(dict.keys.len(), BuildHasherDefault::default()); + FxHashMap::with_capacity_and_hasher(dict.items.len(), BuildHasherDefault::default()); // Detect duplicate keys. - for (i, (key, value)) in dict.keys.iter().zip(dict.values.iter()).enumerate() { + for (i, ast::DictItem { key, value }) in dict.items.iter().enumerate() { let Some(key) = key else { continue; }; @@ -167,20 +167,20 @@ pub(crate) fn repeated_keys(checker: &mut Checker, dict: &ast::ExprDict) { if !seen_values.insert(comparable_value) { diagnostic.set_fix(Fix::unsafe_edit(Edit::deletion( parenthesized_range( - (&dict.values[i - 1]).into(), + dict.value(i - 1).into(), dict.into(), checker.indexer().comment_ranges(), checker.locator().contents(), ) - .unwrap_or(dict.values[i - 1].range()) + .unwrap_or_else(|| dict.value(i - 1).range()) .end(), parenthesized_range( - (&dict.values[i]).into(), + dict.value(i).into(), dict.into(), checker.indexer().comment_ranges(), checker.locator().contents(), ) - .unwrap_or(dict.values[i].range()) + .unwrap_or_else(|| dict.value(i).range()) .end(), ))); } @@ -195,24 +195,24 @@ pub(crate) fn repeated_keys(checker: &mut Checker, dict: &ast::ExprDict) { }, key.range(), ); - let comparable_value: ComparableExpr = (&dict.values[i]).into(); + let comparable_value: ComparableExpr = dict.value(i).into(); if !seen_values.insert(comparable_value) { diagnostic.set_fix(Fix::unsafe_edit(Edit::deletion( parenthesized_range( - (&dict.values[i - 1]).into(), + dict.value(i - 1).into(), dict.into(), checker.indexer().comment_ranges(), checker.locator().contents(), ) - .unwrap_or(dict.values[i - 1].range()) + .unwrap_or_else(|| dict.value(i - 1).range()) .end(), parenthesized_range( - (&dict.values[i]).into(), + dict.value(i).into(), dict.into(), checker.indexer().comment_ranges(), checker.locator().contents(), ) - .unwrap_or(dict.values[i].range()) + .unwrap_or_else(|| dict.value(i).range()) .end(), ))); } diff --git a/crates/ruff_linter/src/rules/pyflakes/rules/strings.rs b/crates/ruff_linter/src/rules/pyflakes/rules/strings.rs index f4f5f94ed9..d61c501bde 100644 --- a/crates/ruff_linter/src/rules/pyflakes/rules/strings.rs +++ b/crates/ruff_linter/src/rules/pyflakes/rules/strings.rs @@ -573,13 +573,12 @@ pub(crate) fn percent_format_extra_named_arguments( return; }; // If any of the keys are spread, abort. - if dict.keys.iter().any(Option::is_none) { + if dict.iter_keys().any(|key| key.is_none()) { return; } let missing: Vec<(usize, &str)> = dict - .keys - .iter() + .iter_keys() .enumerate() .filter_map(|(index, key)| match key { Some(Expr::StringLiteral(ast::ExprStringLiteral { value, .. })) => { @@ -629,16 +628,16 @@ pub(crate) fn percent_format_missing_arguments( return; } - let Expr::Dict(ast::ExprDict { keys, .. }) = &right else { + let Expr::Dict(dict) = &right else { return; }; - if keys.iter().any(Option::is_none) { + if dict.iter_keys().any(|key| key.is_none()) { return; // contains **x splat } let mut keywords = FxHashSet::default(); - for key in keys.iter().flatten() { + for key in dict.iter_keys().flatten() { match key { Expr::StringLiteral(ast::ExprStringLiteral { value, .. }) => { keywords.insert(value.to_str()); diff --git a/crates/ruff_linter/src/rules/pylint/rules/bad_string_format_type.rs b/crates/ruff_linter/src/rules/pylint/rules/bad_string_format_type.rs index 37f38e4bc3..46d242e95e 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/bad_string_format_type.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/bad_string_format_type.rs @@ -170,16 +170,12 @@ fn is_valid_tuple(formats: &[CFormatStrOrBytes], elts: &[Expr]) -> bool } /// Return `true` if the dictionary values align with the format types. -fn is_valid_dict( - formats: &[CFormatStrOrBytes], - keys: &[Option], - values: &[Expr], -) -> bool { +fn is_valid_dict(formats: &[CFormatStrOrBytes], items: &[ast::DictItem]) -> bool { let formats = collect_specs(formats); // If there are more formats that values, the statement is invalid. Avoid // checking the values. - if formats.len() > values.len() { + if formats.len() > items.len() { return true; } @@ -192,7 +188,7 @@ fn is_valid_dict( .map(|mapping_key| (mapping_key.as_str(), format)) }) .collect(); - for (key, value) in keys.iter().zip(values) { + for ast::DictItem { key, value } in items { let Some(key) = key else { return true; }; @@ -252,11 +248,7 @@ pub(crate) fn bad_string_format_type(checker: &mut Checker, expr: &Expr, right: // Parse the parameters. let is_valid = match right { Expr::Tuple(ast::ExprTuple { elts, .. }) => is_valid_tuple(&format_strings, elts), - Expr::Dict(ast::ExprDict { - keys, - values, - range: _, - }) => is_valid_dict(&format_strings, keys, values), + Expr::Dict(ast::ExprDict { items, range: _ }) => is_valid_dict(&format_strings, items), _ => is_valid_constant(&format_strings, right), }; if !is_valid { diff --git a/crates/ruff_linter/src/rules/pylint/rules/dict_iter_missing_items.rs b/crates/ruff_linter/src/rules/pylint/rules/dict_iter_missing_items.rs index e5063808df..28870dda84 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/dict_iter_missing_items.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/dict_iter_missing_items.rs @@ -99,10 +99,10 @@ fn is_dict_key_tuple_with_two_elements(semantic: &SemanticModel, binding: &Bindi return false; }; - dict_expr.keys.iter().all(|elt| { - elt.as_ref().is_some_and(|x| { - if let Some(tuple) = x.as_tuple_expr() { - return tuple.elts.len() == 2; + dict_expr.iter_keys().all(|elt| { + elt.is_some_and(|x| { + if let Expr::Tuple(ExprTuple { elts, .. }) = x { + return elts.len() == 2; } false }) diff --git a/crates/ruff_linter/src/rules/pylint/rules/non_slot_assignment.rs b/crates/ruff_linter/src/rules/pylint/rules/non_slot_assignment.rs index 4c0a98948e..1fa567ff4f 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/non_slot_assignment.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/non_slot_assignment.rs @@ -229,7 +229,7 @@ fn slots_attributes(expr: &Expr) -> impl Iterator { // Ex) `__slots__ = {"name": ...}` let keys_iter = match expr { - Expr::Dict(ast::ExprDict { keys, .. }) => Some(keys.iter().filter_map(|key| match key { + Expr::Dict(dict) => Some(dict.iter_keys().filter_map(|key| match key { Some(Expr::StringLiteral(ast::ExprStringLiteral { value, .. })) => Some(value.to_str()), _ => None, })), diff --git a/crates/ruff_linter/src/rules/pylint/rules/repeated_keyword_argument.rs b/crates/ruff_linter/src/rules/pylint/rules/repeated_keyword_argument.rs index 53099c879d..1ae894a96d 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/repeated_keyword_argument.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/repeated_keyword_argument.rs @@ -4,7 +4,7 @@ use rustc_hash::FxHashSet; use ruff_diagnostics::{Diagnostic, Violation}; use ruff_macros::{derive_message_formats, violation}; -use ruff_python_ast::{Expr, ExprCall, ExprDict, ExprStringLiteral}; +use ruff_python_ast::{Expr, ExprCall, ExprStringLiteral}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -56,9 +56,9 @@ pub(crate) fn repeated_keyword_argument(checker: &mut Checker, call: &ExprCall) keyword.range(), )); } - } else if let Expr::Dict(ExprDict { keys, .. }) = &keyword.value { + } else if let Expr::Dict(dict) = &keyword.value { // Ex) `func(**{"a": 1, "a": 2})` - for key in keys.iter().flatten() { + for key in dict.iter_keys().flatten() { if let Expr::StringLiteral(ExprStringLiteral { value, .. }) = key { if !seen.insert(value.to_str()) { checker.diagnostics.push(Diagnostic::new( diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/convert_typed_dict_functional_to_class.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/convert_typed_dict_functional_to_class.rs index baf1b4c140..cb9948fbfa 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/convert_typed_dict_functional_to_class.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/convert_typed_dict_functional_to_class.rs @@ -163,16 +163,16 @@ fn create_class_def_stmt( .into() } -fn fields_from_dict_literal(keys: &[Option], values: &[Expr]) -> Option> { - if keys.is_empty() { +fn fields_from_dict_literal(items: &[ast::DictItem]) -> Option> { + if items.is_empty() { let node = Stmt::Pass(ast::StmtPass { range: TextRange::default(), }); Some(vec![node]) } else { - keys.iter() - .zip(values.iter()) - .map(|(key, value)| match key { + items + .iter() + .map(|ast::DictItem { key, value }| match key { Some(Expr::StringLiteral(ast::ExprStringLiteral { value: field, .. })) => { if !is_identifier(field.to_str()) { return None; @@ -231,11 +231,9 @@ fn match_fields_and_total(arguments: &Arguments) -> Option<(Vec, Option<&K ([_typename, fields], [..]) => { let total = arguments.find_keyword("total"); match fields { - Expr::Dict(ast::ExprDict { - keys, - values, - range: _, - }) => Some((fields_from_dict_literal(keys, values)?, total)), + Expr::Dict(ast::ExprDict { items, range: _ }) => { + Some((fields_from_dict_literal(items)?, total)) + } Expr::Call(ast::ExprCall { func, arguments: Arguments { keywords, .. }, diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/printf_string_formatting.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/printf_string_formatting.rs index 3c53924d6d..75d325c375 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/printf_string_formatting.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/printf_string_formatting.rs @@ -212,16 +212,11 @@ fn clean_params_tuple<'a>(right: &Expr, locator: &Locator<'a>) -> Cow<'a, str> { fn clean_params_dictionary(right: &Expr, locator: &Locator, stylist: &Stylist) -> Option { let is_multi_line = locator.contains_line_break(right.range()); let mut contents = String::new(); - if let Expr::Dict(ast::ExprDict { - keys, - values, - range: _, - }) = &right - { + if let Expr::Dict(ast::ExprDict { items, range: _ }) = &right { let mut arguments: Vec = vec![]; let mut seen: Vec<&str> = vec![]; let mut indent = None; - for (key, value) in keys.iter().zip(values.iter()) { + for ast::DictItem { key, value } in items { match key { Some(key) => { if let Expr::StringLiteral(ast::ExprStringLiteral { diff --git a/crates/ruff_linter/src/rules/ruff/rules/sort_dunder_slots.rs b/crates/ruff_linter/src/rules/ruff/rules/sort_dunder_slots.rs index 01e4300727..ed308557ae 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/sort_dunder_slots.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/sort_dunder_slots.rs @@ -174,13 +174,9 @@ impl<'a> StringLiteralDisplay<'a> { display_kind, } } - ast::Expr::Dict(ast::ExprDict { - keys, - values, - range, - }) => { - let mut narrowed_keys = Vec::with_capacity(values.len()); - for key in keys { + ast::Expr::Dict(dict @ ast::ExprDict { items, range }) => { + let mut narrowed_keys = Vec::with_capacity(items.len()); + for key in dict.iter_keys() { if let Some(key) = key { // This is somewhat unfortunate, // *but* using a dict for __slots__ is very rare @@ -193,12 +189,11 @@ impl<'a> StringLiteralDisplay<'a> { // `__slots__ = {"foo": "bar", **other_dict}` // If `None` wasn't present in the keys, // the length of the keys should always equal the length of the values - assert_eq!(narrowed_keys.len(), values.len()); - let display_kind = DisplayKind::Dict { values }; + assert_eq!(narrowed_keys.len(), items.len()); Self { elts: Cow::Owned(narrowed_keys), range: *range, - display_kind, + display_kind: DisplayKind::Dict { items }, } } _ => return None, @@ -206,7 +201,7 @@ impl<'a> StringLiteralDisplay<'a> { Some(result) } - fn generate_fix(&self, items: &[&str], checker: &Checker) -> Option { + fn generate_fix(&self, elements: &[&str], checker: &Checker) -> Option { let locator = checker.locator(); let is_multiline = locator.contains_line_break(self.range()); let sorted_source_code = match (&self.display_kind, is_multiline) { @@ -224,12 +219,12 @@ impl<'a> StringLiteralDisplay<'a> { (DisplayKind::Sequence(sequence_kind), false) => sort_single_line_elements_sequence( *sequence_kind, &self.elts, - items, + elements, locator, SORTING_STYLE, ), - (DisplayKind::Dict { values }, false) => { - sort_single_line_elements_dict(&self.elts, items, values, locator) + (DisplayKind::Dict { items }, false) => { + sort_single_line_elements_dict(&self.elts, elements, items, locator) } }; Some(Fix::safe_edit(Edit::range_replacement( @@ -245,7 +240,7 @@ impl<'a> StringLiteralDisplay<'a> { #[derive(Debug)] enum DisplayKind<'a> { Sequence(SequenceKind), - Dict { values: &'a [ast::Expr] }, + Dict { items: &'a [ast::DictItem] }, } /// A newtype that zips together three iterables: @@ -262,14 +257,14 @@ enum DisplayKind<'a> { struct DictElements<'a>(Vec<(&'a &'a str, &'a ast::Expr, &'a ast::Expr)>); impl<'a> DictElements<'a> { - fn new(elements: &'a [&str], key_elts: &'a [ast::Expr], value_elts: &'a [ast::Expr]) -> Self { + fn new(elements: &'a [&str], key_elts: &'a [ast::Expr], items: &'a [ast::DictItem]) -> Self { assert_eq!(key_elts.len(), elements.len()); - assert_eq!(elements.len(), value_elts.len()); + assert_eq!(elements.len(), items.len()); assert!( elements.len() >= 2, "A sequence with < 2 elements cannot be unsorted" ); - Self(izip!(elements, key_elts, value_elts).collect()) + Self(izip!(elements, key_elts, items.iter().map(|item| &item.value)).collect()) } fn last_item_index(&self) -> usize { @@ -294,13 +289,13 @@ impl<'a> DictElements<'a> { /// `sequence_sorting.rs` if any other modules need it, /// but stays here for now, since this is currently the /// only module that needs it -fn sort_single_line_elements_dict( - key_elts: &[ast::Expr], - elements: &[&str], - value_elts: &[ast::Expr], +fn sort_single_line_elements_dict<'a>( + key_elts: &'a [ast::Expr], + elements: &'a [&str], + original_items: &'a [ast::DictItem], locator: &Locator, ) -> String { - let element_trios = DictElements::new(elements, key_elts, value_elts); + let element_trios = DictElements::new(elements, key_elts, original_items); let last_item_index = element_trios.last_item_index(); let mut result = String::from('{'); // We grab the original source-code ranges using `locator.slice()` diff --git a/crates/ruff_python_ast/src/comparable.rs b/crates/ruff_python_ast/src/comparable.rs index b19c320344..369bc84aaf 100644 --- a/crates/ruff_python_ast/src/comparable.rs +++ b/crates/ruff_python_ast/src/comparable.rs @@ -687,10 +687,24 @@ pub struct ExprIf<'a> { orelse: Box>, } +#[derive(Debug, PartialEq, Eq, Hash)] +pub struct ComparableDictItem<'a> { + key: Option>, + 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>>, - values: Vec>, + items: Vec>, } #[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(), diff --git a/crates/ruff_python_ast/src/helpers.rs b/crates/ruff_python_ast/src/helpers.rs index 7213355ff6..eab3d17060 100644 --- a/crates/ruff_python_ast/src/helpers.rs +++ b/crates/ruff_python_ast/src/helpers.rs @@ -155,14 +155,12 @@ pub fn any_over_expr(expr: &Expr, func: &dyn Fn(&Expr) -> bool) -> bool { orelse, range: _, }) => any_over_expr(test, func) || any_over_expr(body, func) || any_over_expr(orelse, func), - Expr::Dict(ast::ExprDict { - keys, - values, - range: _, - }) => values - .iter() - .chain(keys.iter().flatten()) - .any(|expr| any_over_expr(expr, func)), + Expr::Dict(ast::ExprDict { items, range: _ }) => { + items.iter().any(|ast::DictItem { key, value }| { + any_over_expr(value, func) + || key.as_ref().is_some_and(|key| any_over_expr(key, func)) + }) + } Expr::Set(ast::ExprSet { elts, range: _ }) | Expr::List(ast::ExprList { elts, range: _, .. }) | Expr::Tuple(ast::ExprTuple { elts, range: _, .. }) => { @@ -1188,8 +1186,8 @@ impl Truthiness { Self::Truthy } } - Expr::Dict(ast::ExprDict { keys, .. }) => { - if keys.is_empty() { + Expr::Dict(ast::ExprDict { items, .. }) => { + if items.is_empty() { Self::Falsey } else { Self::Truthy diff --git a/crates/ruff_python_ast/src/node.rs b/crates/ruff_python_ast/src/node.rs index d3192e2750..d8c2e3eacf 100644 --- a/crates/ruff_python_ast/src/node.rs +++ b/crates/ruff_python_ast/src/node.rs @@ -2301,13 +2301,9 @@ impl AstNode for ast::ExprDict { where V: PreorderVisitor<'a> + ?Sized, { - let ast::ExprDict { - keys, - values, - range: _, - } = self; + let ast::ExprDict { items, range: _ } = self; - for (key, value) in keys.iter().zip(values) { + for ast::DictItem { key, value } in items { if let Some(key) = key { visitor.visit_expr(key); } diff --git a/crates/ruff_python_ast/src/nodes.rs b/crates/ruff_python_ast/src/nodes.rs index 25c00f0dbe..babba89fc2 100644 --- a/crates/ruff_python_ast/src/nodes.rs +++ b/crates/ruff_python_ast/src/nodes.rs @@ -767,12 +767,89 @@ impl From for Expr { } } +/// Represents an item in a [dictionary literal display][1]. +/// +/// Consider the following Python dictionary literal: +/// ```python +/// {key1: value1, **other_dictionary} +/// ``` +/// +/// In our AST, this would be represented using an `ExprDict` node containing +/// two `DictItem` nodes inside it: +/// ```ignore +/// [ +/// DictItem { +/// key: Some(Expr::Name(ExprName { id: "key1" })), +/// value: Expr::Name(ExprName { id: "value1" }), +/// }, +/// DictItem { +/// key: None, +/// value: Expr::Name(ExprName { id: "other_dictionary" }), +/// } +/// ] +/// ``` +/// +/// [1]: https://docs.python.org/3/reference/expressions.html#displays-for-lists-sets-and-dictionaries +#[derive(Debug, Clone, PartialEq)] +pub struct DictItem { + pub key: Option, + pub value: Expr, +} + +impl DictItem { + fn key(&self) -> Option<&Expr> { + self.key.as_ref() + } + + fn value(&self) -> &Expr { + &self.value + } +} + +impl Ranged for DictItem { + fn range(&self) -> TextRange { + TextRange::new( + self.key.as_ref().map_or(self.value.start(), Ranged::start), + self.value.end(), + ) + } +} + /// See also [Dict](https://docs.python.org/3/library/ast.html#ast.Dict) #[derive(Clone, Debug, PartialEq)] pub struct ExprDict { pub range: TextRange, - pub keys: Vec>, - pub values: Vec, + pub items: Vec, +} + +impl ExprDict { + /// Returns an `Iterator` over the AST nodes representing the + /// dictionary's keys. + pub fn iter_keys(&self) -> DictKeyIterator { + DictKeyIterator::new(&self.items) + } + + /// Returns an `Iterator` over the AST nodes representing the + /// dictionary's values. + pub fn iter_values(&self) -> DictValueIterator { + DictValueIterator::new(&self.items) + } + + /// Returns the AST node representing the *n*th key of this + /// dictionary. + /// + /// Panics: If the index `n` is out of bounds. + pub fn key(&self, n: usize) -> Option<&Expr> { + self.items[n].key() + } + + /// Returns the AST node representing the *n*th value of this + /// dictionary. + /// + /// Panics: If the index `n` is out of bounds. + pub fn value(&self, n: usize) -> &Expr { + self.items[n].value() + } } impl From for Expr { @@ -781,6 +858,90 @@ impl From for Expr { } } +#[derive(Debug, Clone)] +pub struct DictKeyIterator<'a> { + items: Iter<'a, DictItem>, +} + +impl<'a> DictKeyIterator<'a> { + fn new(items: &'a [DictItem]) -> Self { + Self { + items: items.iter(), + } + } + + pub fn is_empty(&self) -> bool { + self.len() == 0 + } +} + +impl<'a> Iterator for DictKeyIterator<'a> { + type Item = Option<&'a Expr>; + + fn next(&mut self) -> Option { + self.items.next().map(DictItem::key) + } + + fn last(mut self) -> Option { + self.next_back() + } + + fn size_hint(&self) -> (usize, Option) { + self.items.size_hint() + } +} + +impl<'a> DoubleEndedIterator for DictKeyIterator<'a> { + fn next_back(&mut self) -> Option { + self.items.next_back().map(DictItem::key) + } +} + +impl<'a> FusedIterator for DictKeyIterator<'a> {} +impl<'a> ExactSizeIterator for DictKeyIterator<'a> {} + +#[derive(Debug, Clone)] +pub struct DictValueIterator<'a> { + items: Iter<'a, DictItem>, +} + +impl<'a> DictValueIterator<'a> { + fn new(items: &'a [DictItem]) -> Self { + Self { + items: items.iter(), + } + } + + pub fn is_empty(&self) -> bool { + self.len() == 0 + } +} + +impl<'a> Iterator for DictValueIterator<'a> { + type Item = &'a Expr; + + fn next(&mut self) -> Option { + self.items.next().map(DictItem::value) + } + + fn last(mut self) -> Option { + self.next_back() + } + + fn size_hint(&self) -> (usize, Option) { + self.items.size_hint() + } +} + +impl<'a> DoubleEndedIterator for DictValueIterator<'a> { + fn next_back(&mut self) -> Option { + self.items.next_back().map(DictItem::value) + } +} + +impl<'a> FusedIterator for DictValueIterator<'a> {} +impl<'a> ExactSizeIterator for DictValueIterator<'a> {} + /// See also [Set](https://docs.python.org/3/library/ast.html#ast.Set) #[derive(Clone, Debug, PartialEq)] pub struct ExprSet { @@ -4358,7 +4519,7 @@ mod tests { assert_eq!(std::mem::size_of::(), 40); assert_eq!(std::mem::size_of::(), 56); assert_eq!(std::mem::size_of::(), 48); - assert_eq!(std::mem::size_of::(), 56); + assert_eq!(std::mem::size_of::(), 32); assert_eq!(std::mem::size_of::(), 48); assert_eq!(std::mem::size_of::(), 8); // 56 for Rustc < 1.76 diff --git a/crates/ruff_python_ast/src/visitor.rs b/crates/ruff_python_ast/src/visitor.rs index 86471765cc..bf14e5a0cf 100644 --- a/crates/ruff_python_ast/src/visitor.rs +++ b/crates/ruff_python_ast/src/visitor.rs @@ -389,16 +389,12 @@ pub fn walk_expr<'a, V: Visitor<'a> + ?Sized>(visitor: &mut V, expr: &'a Expr) { visitor.visit_expr(body); visitor.visit_expr(orelse); } - Expr::Dict(ast::ExprDict { - keys, - values, - range: _, - }) => { - for expr in keys.iter().flatten() { - visitor.visit_expr(expr); - } - for expr in values { - visitor.visit_expr(expr); + Expr::Dict(ast::ExprDict { items, range: _ }) => { + for ast::DictItem { key, value } in items { + if let Some(key) = key { + visitor.visit_expr(key); + } + visitor.visit_expr(value); } } Expr::Set(ast::ExprSet { elts, range: _ }) => { diff --git a/crates/ruff_python_ast/src/visitor/transformer.rs b/crates/ruff_python_ast/src/visitor/transformer.rs index 046630605f..9589617ee0 100644 --- a/crates/ruff_python_ast/src/visitor/transformer.rs +++ b/crates/ruff_python_ast/src/visitor/transformer.rs @@ -376,16 +376,12 @@ pub fn walk_expr(visitor: &V, expr: &mut Expr) { visitor.visit_expr(body); visitor.visit_expr(orelse); } - Expr::Dict(ast::ExprDict { - keys, - values, - range: _, - }) => { - for expr in keys.iter_mut().flatten() { - visitor.visit_expr(expr); - } - for expr in values { - visitor.visit_expr(expr); + Expr::Dict(ast::ExprDict { items, range: _ }) => { + for ast::DictItem { key, value } in items { + if let Some(key) = key { + visitor.visit_expr(key); + } + visitor.visit_expr(value); } } Expr::Set(ast::ExprSet { elts, range: _ }) => { diff --git a/crates/ruff_python_codegen/src/generator.rs b/crates/ruff_python_codegen/src/generator.rs index 80f7978449..1c95db1f9c 100644 --- a/crates/ruff_python_codegen/src/generator.rs +++ b/crates/ruff_python_codegen/src/generator.rs @@ -919,22 +919,18 @@ impl<'a> Generator<'a> { self.unparse_expr(orelse, precedence::IF_EXP); }); } - Expr::Dict(ast::ExprDict { - keys, - values, - range: _, - }) => { + Expr::Dict(ast::ExprDict { items, range: _ }) => { self.p("{"); let mut first = true; - for (k, v) in keys.iter().zip(values) { + for ast::DictItem { key, value } in items { self.p_delim(&mut first, ", "); - if let Some(k) = k { - self.unparse_expr(k, precedence::COMMA); + if let Some(key) = key { + self.unparse_expr(key, precedence::COMMA); self.p(": "); - self.unparse_expr(v, precedence::COMMA); + self.unparse_expr(value, precedence::COMMA); } else { self.p("**"); - self.unparse_expr(v, precedence::MAX); + self.unparse_expr(value, precedence::MAX); } } self.p("}"); diff --git a/crates/ruff_python_formatter/src/expression/expr_dict.rs b/crates/ruff_python_formatter/src/expression/expr_dict.rs index b56eb5033e..4e0e3abb5e 100644 --- a/crates/ruff_python_formatter/src/expression/expr_dict.rs +++ b/crates/ruff_python_formatter/src/expression/expr_dict.rs @@ -1,6 +1,5 @@ use ruff_formatter::{format_args, write}; -use ruff_python_ast::AnyNodeRef; -use ruff_python_ast::{Expr, ExprDict}; +use ruff_python_ast::{AnyNodeRef, DictItem, Expr, ExprDict}; use ruff_text_size::{Ranged, TextRange}; use crate::comments::{dangling_comments, leading_comments, SourceComment}; @@ -14,18 +13,12 @@ pub struct FormatExprDict; impl FormatNodeRule for FormatExprDict { fn fmt_fields(&self, item: &ExprDict, f: &mut PyFormatter) -> FormatResult<()> { - let ExprDict { - range: _, - keys, - values, - } = item; - - debug_assert_eq!(keys.len(), values.len()); + let ExprDict { range: _, items } = item; let comments = f.context().comments().clone(); let dangling = comments.dangling(item); - let (Some(key), Some(value)) = (keys.first(), values.first()) else { + let Some(first_dict_item) = items.first() else { return empty_parenthesized("{", dangling, "}").fmt(f); }; @@ -37,17 +30,17 @@ impl FormatNodeRule for FormatExprDict { // y // } // ``` - let (open_parenthesis_comments, key_value_comments) = dangling.split_at( - dangling - .partition_point(|comment| comment.end() < KeyValuePair::new(key, value).start()), - ); + let (open_parenthesis_comments, key_value_comments) = + dangling.split_at(dangling.partition_point(|comment| { + comment.end() < KeyValuePair::new(first_dict_item).start() + })); let format_pairs = format_with(|f| { let mut joiner = f.join_comma_separated(item.end()); let mut key_value_comments = key_value_comments; - for (key, value) in keys.iter().zip(values) { - let mut key_value_pair = KeyValuePair::new(key, value); + for dict_item in items { + let mut key_value_pair = KeyValuePair::new(dict_item); let partition = key_value_comments .partition_point(|comment| comment.start() < key_value_pair.end()); @@ -84,10 +77,10 @@ struct KeyValuePair<'a> { } impl<'a> KeyValuePair<'a> { - fn new(key: &'a Option, value: &'a Expr) -> Self { + fn new(item: &'a DictItem) -> Self { Self { - key, - value, + key: &item.key, + value: &item.value, comments: &[], } } diff --git a/crates/ruff_python_formatter/src/expression/mod.rs b/crates/ruff_python_formatter/src/expression/mod.rs index 2aea69895f..dd8b94c027 100644 --- a/crates/ruff_python_formatter/src/expression/mod.rs +++ b/crates/ruff_python_formatter/src/expression/mod.rs @@ -1059,8 +1059,8 @@ pub(crate) fn has_own_parentheses( } } - Expr::Dict(ast::ExprDict { keys, .. }) => { - if !keys.is_empty() || context.comments().has_dangling(AnyNodeRef::from(expr)) { + Expr::Dict(ast::ExprDict { items, .. }) => { + if !items.is_empty() || context.comments().has_dangling(AnyNodeRef::from(expr)) { Some(OwnParentheses::NonEmpty) } else { Some(OwnParentheses::Empty) @@ -1217,7 +1217,7 @@ pub(crate) fn is_splittable_expression(expr: &Expr, context: &PyFormatContext) - // Sequence types can split if they contain at least one element. Expr::Tuple(tuple) => !tuple.elts.is_empty(), - Expr::Dict(dict) => !dict.values.is_empty(), + Expr::Dict(dict) => !dict.items.is_empty(), Expr::Set(set) => !set.elts.is_empty(), Expr::List(list) => !list.elts.is_empty(), diff --git a/crates/ruff_python_parser/src/parser/expression.rs b/crates/ruff_python_parser/src/parser/expression.rs index 6f1caf3995..5e35eb4d8e 100644 --- a/crates/ruff_python_parser/src/parser/expression.rs +++ b/crates/ruff_python_parser/src/parser/expression.rs @@ -1544,8 +1544,7 @@ impl<'src> Parser<'src> { // Return an empty `DictExpr` when finding a `}` right after the `{` if self.eat(TokenKind::Rbrace) { return Expr::Dict(ast::ExprDict { - keys: vec![], - values: vec![], + items: vec![], range: self.node_range(start), }); } @@ -1794,21 +1793,24 @@ impl<'src> Parser<'src> { self.expect(TokenKind::Comma); } - let mut keys = vec![key]; - let mut values = vec![value]; + let mut items = vec![ast::DictItem { key, value }]; self.parse_comma_separated_list(RecoveryContextKind::DictElements, |parser| { if parser.eat(TokenKind::DoubleStar) { - keys.push(None); - // Handle dictionary unpacking. Here, the grammar is `'**' bitwise_or` // which requires limiting the expression. - values.push(parser.parse_expression_with_bitwise_or_precedence().expr); + items.push(ast::DictItem { + key: None, + value: parser.parse_expression_with_bitwise_or_precedence().expr, + }); } else { - keys.push(Some(parser.parse_conditional_expression_or_higher().expr)); + let key = parser.parse_conditional_expression_or_higher().expr; parser.expect(TokenKind::Colon); - values.push(parser.parse_conditional_expression_or_higher().expr); + items.push(ast::DictItem { + key: Some(key), + value: parser.parse_conditional_expression_or_higher().expr, + }); } }); @@ -1816,8 +1818,7 @@ impl<'src> Parser<'src> { ast::ExprDict { range: self.node_range(start), - keys, - values, + items, } } diff --git a/crates/ruff_python_parser/src/parser/recovery.rs b/crates/ruff_python_parser/src/parser/recovery.rs index 9d25c99ccd..8687b8c95f 100644 --- a/crates/ruff_python_parser/src/parser/recovery.rs +++ b/crates/ruff_python_parser/src/parser/recovery.rs @@ -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::>(); - let mut values = patterns + let mut items: Vec = keys .into_iter() - .map(pattern_to_expr) - .collect::>(); + .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, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__double_star.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__double_star.py.snap index 0919f80d12..bc87a11aba 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__double_star.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__double_star.py.snap @@ -15,34 +15,36 @@ Module( value: Dict( ExprDict { range: 125..135, - keys: [ - None, - Some( - NumberLiteral( - ExprNumberLiteral { - range: 133..134, - value: Int( - 1, - ), + items: [ + DictItem { + key: None, + value: Name( + ExprName { + range: 128..129, + id: "x", + ctx: Load, }, ), - ), - ], - values: [ - Name( - ExprName { - range: 128..129, - id: "x", - ctx: Load, - }, - ), - Name( - ExprName { - range: 134..134, - id: "", - ctx: Invalid, - }, - ), + }, + DictItem { + key: Some( + NumberLiteral( + ExprNumberLiteral { + range: 133..134, + value: Int( + 1, + ), + }, + ), + ), + value: Name( + ExprName { + range: 134..134, + id: "", + ctx: Invalid, + }, + ), + }, ], }, ), @@ -54,52 +56,54 @@ Module( value: Dict( ExprDict { range: 136..162, - keys: [ - Some( - Name( - ExprName { - range: 137..138, - id: "a", - ctx: Load, + items: [ + DictItem { + key: Some( + Name( + ExprName { + range: 137..138, + id: "a", + ctx: Load, + }, + ), + ), + value: NumberLiteral( + ExprNumberLiteral { + range: 140..141, + value: Int( + 1, + ), }, ), - ), - None, - ], - values: [ - NumberLiteral( - ExprNumberLiteral { - range: 140..141, - value: Int( - 1, - ), - }, - ), - If( - ExprIf { - range: 145..161, - test: BooleanLiteral( - ExprBooleanLiteral { - range: 150..154, - value: true, - }, - ), - body: Name( - ExprName { - range: 145..146, - id: "x", - ctx: Load, - }, - ), - orelse: Name( - ExprName { - range: 160..161, - id: "y", - ctx: Load, - }, - ), - }, - ), + }, + DictItem { + key: None, + value: If( + ExprIf { + range: 145..161, + test: BooleanLiteral( + ExprBooleanLiteral { + range: 150..154, + value: true, + }, + ), + body: Name( + ExprName { + range: 145..146, + id: "x", + ctx: Load, + }, + ), + orelse: Name( + ExprName { + range: 160..161, + id: "y", + ctx: Load, + }, + ), + }, + ), + }, ], }, ), @@ -111,62 +115,64 @@ Module( value: Dict( ExprDict { range: 163..184, - keys: [ - None, - Some( - Name( - ExprName { - range: 179..180, - id: "b", - ctx: Load, + items: [ + DictItem { + key: None, + value: Lambda( + ExprLambda { + range: 166..177, + parameters: Some( + Parameters { + range: 173..174, + posonlyargs: [], + args: [ + ParameterWithDefault { + range: 173..174, + parameter: Parameter { + range: 173..174, + name: Identifier { + id: "x", + range: 173..174, + }, + annotation: None, + }, + default: None, + }, + ], + vararg: None, + kwonlyargs: [], + kwarg: None, + }, + ), + body: Name( + ExprName { + range: 176..177, + id: "x", + ctx: Load, + }, + ), }, ), - ), - ], - values: [ - Lambda( - ExprLambda { - range: 166..177, - parameters: Some( - Parameters { - range: 173..174, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 173..174, - parameter: Parameter { - range: 173..174, - name: Identifier { - id: "x", - range: 173..174, - }, - annotation: None, - }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: Name( + }, + DictItem { + key: Some( + Name( ExprName { - range: 176..177, - id: "x", + range: 179..180, + id: "b", ctx: Load, }, ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 182..183, - value: Int( - 2, - ), - }, - ), + ), + value: NumberLiteral( + ExprNumberLiteral { + range: 182..183, + value: Int( + 2, + ), + }, + ), + }, ], }, ), @@ -178,49 +184,51 @@ Module( value: Dict( ExprDict { range: 185..201, - keys: [ - Some( - Name( - ExprName { - range: 186..187, - id: "a", - ctx: Load, + items: [ + DictItem { + key: Some( + Name( + ExprName { + range: 186..187, + id: "a", + ctx: Load, + }, + ), + ), + value: NumberLiteral( + ExprNumberLiteral { + range: 189..190, + value: Int( + 1, + ), }, ), - ), - None, - ], - values: [ - NumberLiteral( - ExprNumberLiteral { - range: 189..190, - value: Int( - 1, - ), - }, - ), - BoolOp( - ExprBoolOp { - range: 194..200, - op: Or, - values: [ - Name( - ExprName { - range: 194..195, - id: "x", - ctx: Load, - }, - ), - Name( - ExprName { - range: 199..200, - id: "y", - ctx: Load, - }, - ), - ], - }, - ), + }, + DictItem { + key: None, + value: BoolOp( + ExprBoolOp { + range: 194..200, + op: Or, + values: [ + Name( + ExprName { + range: 194..195, + id: "x", + ctx: Load, + }, + ), + Name( + ExprName { + range: 199..200, + id: "y", + ctx: Load, + }, + ), + ], + }, + ), + }, ], }, ), @@ -232,49 +240,51 @@ Module( value: Dict( ExprDict { range: 202..219, - keys: [ - None, - Some( - Name( - ExprName { - range: 214..215, - id: "b", - ctx: Load, + items: [ + DictItem { + key: None, + value: BoolOp( + ExprBoolOp { + range: 205..212, + op: And, + values: [ + Name( + ExprName { + range: 205..206, + id: "x", + ctx: Load, + }, + ), + Name( + ExprName { + range: 211..212, + id: "y", + ctx: Load, + }, + ), + ], }, ), - ), - ], - values: [ - BoolOp( - ExprBoolOp { - range: 205..212, - op: And, - values: [ - Name( - ExprName { - range: 205..206, - id: "x", - ctx: Load, - }, - ), - Name( - ExprName { - range: 211..212, - id: "y", - ctx: Load, - }, - ), - ], - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 217..218, - value: Int( - 2, + }, + DictItem { + key: Some( + Name( + ExprName { + range: 214..215, + id: "b", + ctx: Load, + }, ), - }, - ), + ), + value: NumberLiteral( + ExprNumberLiteral { + range: 217..218, + value: Int( + 2, + ), + }, + ), + }, ], }, ), @@ -286,57 +296,61 @@ Module( value: Dict( ExprDict { range: 220..241, - keys: [ - Some( - Name( - ExprName { - range: 221..222, - id: "a", - ctx: Load, - }, - ), - ), - None, - Some( - Name( - ExprName { - range: 236..237, - id: "b", - ctx: Load, - }, - ), - ), - ], - values: [ - NumberLiteral( - ExprNumberLiteral { - range: 224..225, - value: Int( - 1, - ), - }, - ), - UnaryOp( - ExprUnaryOp { - range: 229..234, - op: Not, - operand: Name( + items: [ + DictItem { + key: Some( + Name( ExprName { - range: 233..234, - id: "x", + range: 221..222, + id: "a", ctx: Load, }, ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 239..240, - value: Int( - 2, + ), + value: NumberLiteral( + ExprNumberLiteral { + range: 224..225, + value: Int( + 1, + ), + }, + ), + }, + DictItem { + key: None, + value: UnaryOp( + ExprUnaryOp { + range: 229..234, + op: Not, + operand: Name( + ExprName { + range: 233..234, + id: "x", + ctx: Load, + }, + ), + }, + ), + }, + DictItem { + key: Some( + Name( + ExprName { + range: 236..237, + id: "b", + ctx: Load, + }, ), - }, - ), + ), + value: NumberLiteral( + ExprNumberLiteral { + range: 239..240, + value: Int( + 2, + ), + }, + ), + }, ], }, ), @@ -348,34 +362,34 @@ Module( value: Dict( ExprDict { range: 242..252, - keys: [ - None, - ], - values: [ - Compare( - ExprCompare { - range: 245..251, - left: Name( - ExprName { - range: 245..246, - id: "x", - ctx: Load, - }, - ), - ops: [ - In, - ], - comparators: [ - Name( + items: [ + DictItem { + key: None, + value: Compare( + ExprCompare { + range: 245..251, + left: Name( ExprName { - range: 250..251, - id: "y", + range: 245..246, + id: "x", ctx: Load, }, ), - ], - }, - ), + ops: [ + In, + ], + comparators: [ + Name( + ExprName { + range: 250..251, + id: "y", + ctx: Load, + }, + ), + ], + }, + ), + }, ], }, ), @@ -387,34 +401,34 @@ Module( value: Dict( ExprDict { range: 253..267, - keys: [ - None, - ], - values: [ - Compare( - ExprCompare { - range: 256..266, - left: Name( - ExprName { - range: 256..257, - id: "x", - ctx: Load, - }, - ), - ops: [ - NotIn, - ], - comparators: [ - Name( + items: [ + DictItem { + key: None, + value: Compare( + ExprCompare { + range: 256..266, + left: Name( ExprName { - range: 265..266, - id: "y", + range: 256..257, + id: "x", ctx: Load, }, ), - ], - }, - ), + ops: [ + NotIn, + ], + comparators: [ + Name( + ExprName { + range: 265..266, + id: "y", + ctx: Load, + }, + ), + ], + }, + ), + }, ], }, ), @@ -426,34 +440,34 @@ Module( value: Dict( ExprDict { range: 268..277, - keys: [ - None, - ], - values: [ - Compare( - ExprCompare { - range: 271..276, - left: Name( - ExprName { - range: 271..272, - id: "x", - ctx: Load, - }, - ), - ops: [ - Lt, - ], - comparators: [ - Name( + items: [ + DictItem { + key: None, + value: Compare( + ExprCompare { + range: 271..276, + left: Name( ExprName { - range: 275..276, - id: "y", + range: 271..272, + id: "x", ctx: Load, }, ), - ], - }, - ), + ops: [ + Lt, + ], + comparators: [ + Name( + ExprName { + range: 275..276, + id: "y", + ctx: Load, + }, + ), + ], + }, + ), + }, ], }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__double_star_comprehension.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__double_star_comprehension.py.snap index d1711b33ca..a5e9951e6d 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__double_star_comprehension.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__double_star_comprehension.py.snap @@ -15,82 +15,88 @@ Module( value: Dict( ExprDict { range: 122..147, - keys: [ - None, - Some( - Name( + items: [ + DictItem { + key: None, + value: Name( ExprName { - range: 128..129, - id: "y", - ctx: Load, - }, - ), - ), - Some( - Name( - ExprName { - range: 134..135, + range: 125..126, id: "x", ctx: Load, }, ), - ), - Some( - Compare( - ExprCompare { - range: 137..146, - left: Name( - ExprName { - range: 137..138, - id: "y", - ctx: Load, - }, - ), - ops: [ - In, - ], - comparators: [ - Name( + }, + DictItem { + key: Some( + Name( + ExprName { + range: 128..129, + id: "y", + ctx: Load, + }, + ), + ), + value: Name( + ExprName { + range: 130..133, + id: "for", + ctx: Load, + }, + ), + }, + DictItem { + key: Some( + Name( + ExprName { + range: 134..135, + id: "x", + ctx: Load, + }, + ), + ), + value: Name( + ExprName { + range: 135..135, + id: "", + ctx: Invalid, + }, + ), + }, + DictItem { + key: Some( + Compare( + ExprCompare { + range: 137..146, + left: Name( ExprName { - range: 142..146, - id: "data", + range: 137..138, + id: "y", ctx: Load, }, ), - ], + ops: [ + In, + ], + comparators: [ + Name( + ExprName { + range: 142..146, + id: "data", + ctx: Load, + }, + ), + ], + }, + ), + ), + value: Name( + ExprName { + range: 146..146, + id: "", + ctx: Invalid, }, ), - ), - ], - values: [ - Name( - ExprName { - range: 125..126, - id: "x", - ctx: Load, - }, - ), - Name( - ExprName { - range: 130..133, - id: "for", - ctx: Load, - }, - ), - Name( - ExprName { - range: 135..135, - id: "", - ctx: Invalid, - }, - ), - Name( - ExprName { - range: 146..146, - id: "", - ctx: Invalid, - }, - ), + }, ], }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__missing_closing_brace_0.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__missing_closing_brace_0.py.snap index 0075084040..f672965118 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__missing_closing_brace_0.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__missing_closing_brace_0.py.snap @@ -15,51 +15,53 @@ Module( value: Dict( ExprDict { range: 0..24, - keys: [ - Some( - Name( + items: [ + DictItem { + key: Some( + Name( + ExprName { + range: 1..2, + id: "x", + ctx: Load, + }, + ), + ), + value: Name( ExprName { - range: 1..2, - id: "x", + range: 5..8, + id: "def", ctx: Load, }, ), - ), - Some( - Call( - ExprCall { - range: 9..14, - func: Name( - ExprName { - range: 9..12, - id: "foo", - ctx: Load, + }, + DictItem { + key: Some( + Call( + ExprCall { + range: 9..14, + func: Name( + ExprName { + range: 9..12, + id: "foo", + ctx: Load, + }, + ), + arguments: Arguments { + range: 12..14, + args: [], + keywords: [], }, - ), - arguments: Arguments { - range: 12..14, - args: [], - keywords: [], }, + ), + ), + value: Name( + ExprName { + range: 20..24, + id: "pass", + ctx: Load, }, ), - ), - ], - values: [ - Name( - ExprName { - range: 5..8, - id: "def", - ctx: Load, - }, - ), - Name( - ExprName { - range: 20..24, - id: "pass", - ctx: Load, - }, - ), + }, ], }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__missing_closing_brace_1.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__missing_closing_brace_1.py.snap index 98278802e7..e475ac928d 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__missing_closing_brace_1.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__missing_closing_brace_1.py.snap @@ -15,40 +15,40 @@ Module( value: Dict( ExprDict { range: 0..10, - keys: [ - Some( - Name( - ExprName { - range: 1..2, - id: "x", - ctx: Load, + items: [ + DictItem { + key: Some( + Name( + ExprName { + range: 1..2, + id: "x", + ctx: Load, + }, + ), + ), + value: BinOp( + ExprBinOp { + range: 5..10, + left: NumberLiteral( + ExprNumberLiteral { + range: 5..6, + value: Int( + 1, + ), + }, + ), + op: Add, + right: NumberLiteral( + ExprNumberLiteral { + range: 9..10, + value: Int( + 2, + ), + }, + ), }, ), - ), - ], - values: [ - BinOp( - ExprBinOp { - range: 5..10, - left: NumberLiteral( - ExprNumberLiteral { - range: 5..6, - value: Int( - 1, - ), - }, - ), - op: Add, - right: NumberLiteral( - ExprNumberLiteral { - range: 9..10, - value: Int( - 2, - ), - }, - ), - }, - ), + }, ], }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__missing_closing_brace_2.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__missing_closing_brace_2.py.snap index 1dd134ac77..d60ca66d0a 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__missing_closing_brace_2.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__missing_closing_brace_2.py.snap @@ -15,26 +15,26 @@ Module( value: Dict( ExprDict { range: 0..6, - keys: [ - Some( - Name( - ExprName { - range: 1..2, - id: "x", - ctx: Load, + items: [ + DictItem { + key: Some( + Name( + ExprName { + range: 1..2, + id: "x", + ctx: Load, + }, + ), + ), + value: NumberLiteral( + ExprNumberLiteral { + range: 4..5, + value: Int( + 1, + ), }, ), - ), - ], - values: [ - NumberLiteral( - ExprNumberLiteral { - range: 4..5, - value: Int( - 1, - ), - }, - ), + }, ], }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__named_expression_0.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__named_expression_0.py.snap index bddf3d3b1d..311a18cd33 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__named_expression_0.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__named_expression_0.py.snap @@ -15,71 +15,75 @@ Module( value: Dict( ExprDict { range: 55..77, - keys: [ - Some( - Named( - ExprNamed { - range: 56..62, - target: Name( - ExprName { - range: 56..57, - id: "x", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 61..62, - value: Int( - 1, - ), - }, - ), - }, + items: [ + DictItem { + key: Some( + Named( + ExprNamed { + range: 56..62, + target: Name( + ExprName { + range: 56..57, + id: "x", + ctx: Store, + }, + ), + value: NumberLiteral( + ExprNumberLiteral { + range: 61..62, + value: Int( + 1, + ), + }, + ), + }, + ), ), - ), - Some( - Name( + value: Name( ExprName { - range: 67..68, - id: "z", + range: 64..65, + id: "y", ctx: Load, }, ), - ), - Some( - NumberLiteral( - ExprNumberLiteral { - range: 72..73, - value: Int( - 2, - ), + }, + DictItem { + key: Some( + Name( + ExprName { + range: 67..68, + id: "z", + ctx: Load, + }, + ), + ), + value: Name( + ExprName { + range: 68..68, + id: "", + ctx: Invalid, }, ), - ), - ], - values: [ - Name( - ExprName { - range: 64..65, - id: "y", - ctx: Load, - }, - ), - Name( - ExprName { - range: 68..68, - id: "", - ctx: Invalid, - }, - ), - Name( - ExprName { - range: 75..76, - id: "a", - ctx: Load, - }, - ), + }, + DictItem { + key: Some( + NumberLiteral( + ExprNumberLiteral { + range: 72..73, + value: Int( + 2, + ), + }, + ), + ), + value: Name( + ExprName { + range: 75..76, + id: "a", + ctx: Load, + }, + ), + }, ], }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__named_expression_1.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__named_expression_1.py.snap index e2aabe28da..09964f98bf 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__named_expression_1.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__named_expression_1.py.snap @@ -15,75 +15,81 @@ Module( value: Dict( ExprDict { range: 57..79, - keys: [ - Some( - Name( + items: [ + DictItem { + key: Some( + Name( + ExprName { + range: 58..59, + id: "x", + ctx: Load, + }, + ), + ), + value: Name( ExprName { - range: 58..59, - id: "x", + range: 61..62, + id: "y", ctx: Load, }, ), - ), - Some( - NumberLiteral( - ExprNumberLiteral { - range: 66..67, - value: Int( - 1, - ), + }, + DictItem { + key: Some( + NumberLiteral( + ExprNumberLiteral { + range: 66..67, + value: Int( + 1, + ), + }, + ), + ), + value: Name( + ExprName { + range: 67..67, + id: "", + ctx: Invalid, }, ), - ), - Some( - Name( + }, + DictItem { + key: Some( + Name( + ExprName { + range: 69..70, + id: "z", + ctx: Load, + }, + ), + ), + value: Name( ExprName { - range: 69..70, - id: "z", + range: 72..73, + id: "a", ctx: Load, }, ), - ), - Some( - NumberLiteral( - ExprNumberLiteral { - range: 77..78, - value: Int( - 2, - ), + }, + DictItem { + key: Some( + NumberLiteral( + ExprNumberLiteral { + range: 77..78, + value: Int( + 2, + ), + }, + ), + ), + value: Name( + ExprName { + range: 78..78, + id: "", + ctx: Invalid, }, ), - ), - ], - values: [ - Name( - ExprName { - range: 61..62, - id: "y", - ctx: Load, - }, - ), - Name( - ExprName { - range: 67..67, - id: "", - ctx: Invalid, - }, - ), - Name( - ExprName { - range: 72..73, - id: "a", - ctx: Load, - }, - ), - Name( - ExprName { - range: 78..78, - id: "", - ctx: Invalid, - }, - ), + }, ], }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__recover.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__recover.py.snap index c64d7ddf65..4c7b359e7e 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__recover.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__recover.py.snap @@ -34,45 +34,47 @@ Module( value: Dict( ExprDict { range: 93..105, - keys: [ - Some( - NumberLiteral( + items: [ + DictItem { + key: Some( + NumberLiteral( + ExprNumberLiteral { + range: 94..95, + value: Int( + 1, + ), + }, + ), + ), + value: NumberLiteral( ExprNumberLiteral { - range: 94..95, + range: 97..98, value: Int( - 1, + 2, ), }, ), - ), - Some( - NumberLiteral( + }, + DictItem { + key: Some( + NumberLiteral( + ExprNumberLiteral { + range: 100..101, + value: Int( + 3, + ), + }, + ), + ), + value: NumberLiteral( ExprNumberLiteral { - range: 100..101, + range: 103..104, value: Int( - 3, + 4, ), }, ), - ), - ], - values: [ - NumberLiteral( - ExprNumberLiteral { - range: 97..98, - value: Int( - 2, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 103..104, - value: Int( - 4, - ), - }, - ), + }, ], }, ), @@ -84,27 +86,27 @@ Module( value: Dict( ExprDict { range: 107..115, - keys: [ - Some( - NumberLiteral( + items: [ + DictItem { + key: Some( + NumberLiteral( + ExprNumberLiteral { + range: 108..109, + value: Int( + 1, + ), + }, + ), + ), + value: NumberLiteral( ExprNumberLiteral { - range: 108..109, + range: 111..112, value: Int( - 1, + 2, ), }, ), - ), - ], - values: [ - NumberLiteral( - ExprNumberLiteral { - range: 111..112, - value: Int( - 2, - ), - }, - ), + }, ], }, ), @@ -116,45 +118,47 @@ Module( value: Dict( ExprDict { range: 133..144, - keys: [ - Some( - NumberLiteral( + items: [ + DictItem { + key: Some( + NumberLiteral( + ExprNumberLiteral { + range: 134..135, + value: Int( + 1, + ), + }, + ), + ), + value: NumberLiteral( ExprNumberLiteral { - range: 134..135, + range: 137..138, value: Int( - 1, + 2, ), }, ), - ), - Some( - NumberLiteral( + }, + DictItem { + key: Some( + NumberLiteral( + ExprNumberLiteral { + range: 139..140, + value: Int( + 3, + ), + }, + ), + ), + value: NumberLiteral( ExprNumberLiteral { - range: 139..140, + range: 142..143, value: Int( - 3, + 4, ), }, ), - ), - ], - values: [ - NumberLiteral( - ExprNumberLiteral { - range: 137..138, - value: Int( - 2, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 142..143, - value: Int( - 4, - ), - }, - ), + }, ], }, ), @@ -166,26 +170,26 @@ Module( value: Dict( ExprDict { range: 157..162, - keys: [ - Some( - NumberLiteral( - ExprNumberLiteral { - range: 158..159, - value: Int( - 1, - ), + items: [ + DictItem { + key: Some( + NumberLiteral( + ExprNumberLiteral { + range: 158..159, + value: Int( + 1, + ), + }, + ), + ), + value: Name( + ExprName { + range: 160..160, + id: "", + ctx: Invalid, }, ), - ), - ], - values: [ - Name( - ExprName { - range: 160..160, - id: "", - ctx: Invalid, - }, - ), + }, ], }, ), @@ -197,17 +201,17 @@ Module( value: Dict( ExprDict { range: 201..205, - keys: [ - None, - ], - values: [ - Name( - ExprName { - range: 204..204, - id: "", - ctx: Invalid, - }, - ), + items: [ + DictItem { + key: None, + value: Name( + ExprName { + range: 204..204, + id: "", + ctx: Invalid, + }, + ), + }, ], }, ), @@ -219,49 +223,53 @@ Module( value: Dict( ExprDict { range: 206..222, - keys: [ - Some( - Name( + items: [ + DictItem { + key: Some( + Name( + ExprName { + range: 207..208, + id: "x", + ctx: Load, + }, + ), + ), + value: Name( ExprName { - range: 207..208, - id: "x", + range: 210..211, + id: "y", ctx: Load, }, ), - ), - None, - Some( - Name( + }, + DictItem { + key: None, + value: Name( ExprName { - range: 217..218, - id: "a", + range: 215..215, + id: "", + ctx: Invalid, + }, + ), + }, + DictItem { + key: Some( + Name( + ExprName { + range: 217..218, + id: "a", + ctx: Load, + }, + ), + ), + value: Name( + ExprName { + range: 220..221, + id: "b", ctx: Load, }, ), - ), - ], - values: [ - Name( - ExprName { - range: 210..211, - id: "y", - ctx: Load, - }, - ), - Name( - ExprName { - range: 215..215, - id: "", - ctx: Invalid, - }, - ), - Name( - ExprName { - range: 220..221, - id: "b", - ctx: Load, - }, - ), + }, ], }, ), @@ -273,69 +281,73 @@ Module( value: Dict( ExprDict { range: 310..330, - keys: [ - Some( - Starred( - ExprStarred { - range: 311..313, - value: Name( - ExprName { - range: 312..313, - id: "x", - ctx: Load, - }, - ), - ctx: Load, - }, + items: [ + DictItem { + key: Some( + Starred( + ExprStarred { + range: 311..313, + value: Name( + ExprName { + range: 312..313, + id: "x", + ctx: Load, + }, + ), + ctx: Load, + }, + ), ), - ), - Some( - Name( + value: Name( ExprName { - range: 318..319, - id: "z", + range: 315..316, + id: "y", ctx: Load, }, ), - ), - Some( - Starred( - ExprStarred { - range: 324..326, - value: Name( - ExprName { - range: 325..326, - id: "b", - ctx: Load, - }, - ), + }, + DictItem { + key: Some( + Name( + ExprName { + range: 318..319, + id: "z", + ctx: Load, + }, + ), + ), + value: Name( + ExprName { + range: 321..322, + id: "a", ctx: Load, }, ), - ), - ], - values: [ - Name( - ExprName { - range: 315..316, - id: "y", - ctx: Load, - }, - ), - Name( - ExprName { - range: 321..322, - id: "a", - ctx: Load, - }, - ), - Name( - ExprName { - range: 328..329, - id: "c", - ctx: Load, - }, - ), + }, + DictItem { + key: Some( + Starred( + ExprStarred { + range: 324..326, + value: Name( + ExprName { + range: 325..326, + id: "b", + ctx: Load, + }, + ), + ctx: Load, + }, + ), + ), + value: Name( + ExprName { + range: 328..329, + id: "c", + ctx: Load, + }, + ), + }, ], }, ), @@ -347,53 +359,55 @@ Module( value: Dict( ExprDict { range: 331..345, - keys: [ - Some( - Name( - ExprName { - range: 332..333, - id: "x", - ctx: Load, - }, - ), - ), - Some( - Name( - ExprName { - range: 339..340, - id: "z", - ctx: Load, - }, - ), - ), - ], - values: [ - Starred( - ExprStarred { - range: 335..337, - value: Name( + items: [ + DictItem { + key: Some( + Name( ExprName { - range: 336..337, - id: "y", + range: 332..333, + id: "x", ctx: Load, }, ), - ctx: Load, - }, - ), - Starred( - ExprStarred { - range: 342..344, - value: Name( + ), + value: Starred( + ExprStarred { + range: 335..337, + value: Name( + ExprName { + range: 336..337, + id: "y", + ctx: Load, + }, + ), + ctx: Load, + }, + ), + }, + DictItem { + key: Some( + Name( ExprName { - range: 343..344, - id: "a", + range: 339..340, + id: "z", ctx: Load, }, ), - ctx: Load, - }, - ), + ), + value: Starred( + ExprStarred { + range: 342..344, + value: Name( + ExprName { + range: 343..344, + id: "a", + ctx: Load, + }, + ), + ctx: Load, + }, + ), + }, ], }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__set__recover.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__set__recover.py.snap index ba84d23b89..946b061be1 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__set__recover.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__set__recover.py.snap @@ -110,27 +110,27 @@ Module( value: Dict( ExprDict { range: 271..277, - keys: [ - Some( - NumberLiteral( + items: [ + DictItem { + key: Some( + NumberLiteral( + ExprNumberLiteral { + range: 272..273, + value: Int( + 1, + ), + }, + ), + ), + value: NumberLiteral( ExprNumberLiteral { - range: 272..273, + range: 275..276, value: Int( - 1, + 2, ), }, ), - ), - ], - values: [ - NumberLiteral( - ExprNumberLiteral { - range: 275..276, - value: Int( - 2, - ), - }, - ), + }, ], }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@invalid_del_target.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@invalid_del_target.py.snap index 1b2fcfa110..d32507dc88 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@invalid_del_target.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@invalid_del_target.py.snap @@ -44,37 +44,37 @@ Module( Dict( ExprDict { range: 14..22, - keys: [ - Some( - StringLiteral( - ExprStringLiteral { - range: 15..18, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 15..18, - value: "x", - flags: StringLiteralFlags { - quote_style: Single, - prefix: Empty, - triple_quoted: false, + items: [ + DictItem { + key: Some( + StringLiteral( + ExprStringLiteral { + range: 15..18, + value: StringLiteralValue { + inner: Single( + StringLiteral { + range: 15..18, + value: "x", + flags: StringLiteralFlags { + quote_style: Single, + prefix: Empty, + triple_quoted: false, + }, }, - }, - ), + ), + }, }, + ), + ), + value: NumberLiteral( + ExprNumberLiteral { + range: 20..21, + value: Int( + 1, + ), }, ), - ), - ], - values: [ - NumberLiteral( - ExprNumberLiteral { - range: 20..21, - value: Int( - 1, - ), - }, - ), + }, ], }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_var_keyword_with_default.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_var_keyword_with_default.py.snap index 1c83da2091..dd1e0636d5 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_var_keyword_with_default.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_var_keyword_with_default.py.snap @@ -57,65 +57,67 @@ Module( value: Dict( ExprDict { range: 20..36, - keys: [ - Some( - StringLiteral( - ExprStringLiteral { - range: 21..24, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 21..24, - value: "b", - flags: StringLiteralFlags { - quote_style: Single, - prefix: Empty, - triple_quoted: false, + items: [ + DictItem { + key: Some( + StringLiteral( + ExprStringLiteral { + range: 21..24, + value: StringLiteralValue { + inner: Single( + StringLiteral { + range: 21..24, + value: "b", + flags: StringLiteralFlags { + quote_style: Single, + prefix: Empty, + triple_quoted: false, + }, }, - }, - ), + ), + }, }, + ), + ), + value: NumberLiteral( + ExprNumberLiteral { + range: 26..27, + value: Int( + 1, + ), }, ), - ), - Some( - StringLiteral( - ExprStringLiteral { - range: 29..32, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 29..32, - value: "c", - flags: StringLiteralFlags { - quote_style: Single, - prefix: Empty, - triple_quoted: false, + }, + DictItem { + key: Some( + StringLiteral( + ExprStringLiteral { + range: 29..32, + value: StringLiteralValue { + inner: Single( + StringLiteral { + range: 29..32, + value: "c", + flags: StringLiteralFlags { + quote_style: Single, + prefix: Empty, + triple_quoted: false, + }, }, - }, - ), + ), + }, }, + ), + ), + value: NumberLiteral( + ExprNumberLiteral { + range: 34..35, + value: Int( + 2, + ), }, ), - ), - ], - values: [ - NumberLiteral( - ExprNumberLiteral { - range: 26..27, - value: Int( - 1, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 34..35, - value: Int( - 2, - ), - }, - ), + }, ], }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__invalid_assignment_targets.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__invalid_assignment_targets.py.snap index d7812bcae5..393c745df5 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__invalid_assignment_targets.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__invalid_assignment_targets.py.snap @@ -319,37 +319,37 @@ Module( Dict( ExprDict { range: 386..394, - keys: [ - Some( - StringLiteral( - ExprStringLiteral { - range: 387..390, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 387..390, - value: "a", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, + items: [ + DictItem { + key: Some( + StringLiteral( + ExprStringLiteral { + range: 387..390, + value: StringLiteralValue { + inner: Single( + StringLiteral { + range: 387..390, + value: "a", + flags: StringLiteralFlags { + quote_style: Double, + prefix: Empty, + triple_quoted: false, + }, }, - }, - ), + ), + }, }, + ), + ), + value: NumberLiteral( + ExprNumberLiteral { + range: 392..393, + value: Int( + 5, + ), }, ), - ), - ], - values: [ - NumberLiteral( - ExprNumberLiteral { - range: 392..393, - value: Int( - 5, - ), - }, - ), + }, ], }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__invalid_augmented_assignment_target.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__invalid_augmented_assignment_target.py.snap index 9681d152d4..92fa932751 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__invalid_augmented_assignment_target.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__invalid_augmented_assignment_target.py.snap @@ -236,37 +236,37 @@ Module( target: Dict( ExprDict { range: 186..194, - keys: [ - Some( - StringLiteral( - ExprStringLiteral { - range: 187..190, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 187..190, - value: "a", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, + items: [ + DictItem { + key: Some( + StringLiteral( + ExprStringLiteral { + range: 187..190, + value: StringLiteralValue { + inner: Single( + StringLiteral { + range: 187..190, + value: "a", + flags: StringLiteralFlags { + quote_style: Double, + prefix: Empty, + triple_quoted: false, + }, }, - }, - ), + ), + }, }, + ), + ), + value: NumberLiteral( + ExprNumberLiteral { + range: 192..193, + value: Int( + 5, + ), }, ), - ), - ], - values: [ - NumberLiteral( - ExprNumberLiteral { - range: 192..193, - value: Int( - 5, - ), - }, - ), + }, ], }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__as_pattern_3.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__as_pattern_3.py.snap index 857ca2e275..bd6b87ab9f 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__as_pattern_3.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__as_pattern_3.py.snap @@ -28,8 +28,7 @@ Module( cls: Dict( ExprDict { range: 108..109, - keys: [], - values: [], + items: [], }, ), arguments: PatternArguments { diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__invalid_lhs_or_rhs_pattern.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__invalid_lhs_or_rhs_pattern.py.snap index ef1241b3a7..2185fc051d 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__invalid_lhs_or_rhs_pattern.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__invalid_lhs_or_rhs_pattern.py.snap @@ -263,25 +263,25 @@ Module( left: Dict( ExprDict { range: 201..210, - keys: [ - Some( - BooleanLiteral( - ExprBooleanLiteral { - range: 202..206, - value: true, + items: [ + DictItem { + key: Some( + BooleanLiteral( + ExprBooleanLiteral { + range: 202..206, + value: true, + }, + ), + ), + value: NumberLiteral( + ExprNumberLiteral { + range: 208..209, + value: Int( + 1, + ), }, ), - ), - ], - values: [ - NumberLiteral( - ExprNumberLiteral { - range: 208..209, - value: Int( - 1, - ), - }, - ), + }, ], }, ), @@ -711,25 +711,25 @@ Module( right: Dict( ExprDict { range: 534..543, - keys: [ - Some( - BooleanLiteral( - ExprBooleanLiteral { - range: 535..539, - value: true, + items: [ + DictItem { + key: Some( + BooleanLiteral( + ExprBooleanLiteral { + range: 535..539, + value: true, + }, + ), + ), + value: NumberLiteral( + ExprNumberLiteral { + range: 541..542, + value: Int( + 1, + ), }, ), - ), - ], - values: [ - NumberLiteral( - ExprNumberLiteral { - range: 541..542, - value: Int( - 1, - ), - }, - ), + }, ], }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__await.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__await.py.snap index 120bcda083..e000166f05 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__await.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__await.py.snap @@ -192,26 +192,26 @@ Module( value: Dict( ExprDict { range: 76..82, - keys: [ - Some( - Name( - ExprName { - range: 77..78, - id: "i", - ctx: Load, + items: [ + DictItem { + key: Some( + Name( + ExprName { + range: 77..78, + id: "i", + ctx: Load, + }, + ), + ), + value: NumberLiteral( + ExprNumberLiteral { + range: 80..81, + value: Int( + 5, + ), }, ), - ), - ], - values: [ - NumberLiteral( - ExprNumberLiteral { - range: 80..81, - value: Int( - 5, - ), - }, - ), + }, ], }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__call.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__call.py.snap index 968d389285..7234aa72ad 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__call.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__call.py.snap @@ -360,45 +360,47 @@ Module( func: Dict( ExprDict { range: 219..231, - keys: [ - Some( - NumberLiteral( + items: [ + DictItem { + key: Some( + NumberLiteral( + ExprNumberLiteral { + range: 220..221, + value: Int( + 1, + ), + }, + ), + ), + value: NumberLiteral( ExprNumberLiteral { - range: 220..221, + range: 223..224, value: Int( - 1, + 2, ), }, ), - ), - Some( - NumberLiteral( + }, + DictItem { + key: Some( + NumberLiteral( + ExprNumberLiteral { + range: 226..227, + value: Int( + 3, + ), + }, + ), + ), + value: NumberLiteral( ExprNumberLiteral { - range: 226..227, + range: 229..230, value: Int( - 3, + 4, ), }, ), - ), - ], - values: [ - NumberLiteral( - ExprNumberLiteral { - range: 223..224, - value: Int( - 2, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 229..230, - value: Int( - 4, - ), - }, - ), + }, ], }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__dictionary.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__dictionary.py.snap index 55547247c8..502274b405 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__dictionary.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__dictionary.py.snap @@ -15,8 +15,7 @@ Module( value: Dict( ExprDict { range: 9..11, - keys: [], - values: [], + items: [], }, ), }, @@ -27,27 +26,27 @@ Module( value: Dict( ExprDict { range: 12..18, - keys: [ - Some( - NumberLiteral( + items: [ + DictItem { + key: Some( + NumberLiteral( + ExprNumberLiteral { + range: 13..14, + value: Int( + 1, + ), + }, + ), + ), + value: NumberLiteral( ExprNumberLiteral { - range: 13..14, + range: 16..17, value: Int( - 1, + 2, ), }, ), - ), - ], - values: [ - NumberLiteral( - ExprNumberLiteral { - range: 16..17, - value: Int( - 2, - ), - }, - ), + }, ], }, ), @@ -59,71 +58,75 @@ Module( value: Dict( ExprDict { range: 19..43, - keys: [ - Some( - NumberLiteral( + items: [ + DictItem { + key: Some( + NumberLiteral( + ExprNumberLiteral { + range: 20..21, + value: Int( + 1, + ), + }, + ), + ), + value: NumberLiteral( ExprNumberLiteral { - range: 20..21, + range: 23..24, + value: Int( + 2, + ), + }, + ), + }, + DictItem { + key: Some( + Name( + ExprName { + range: 26..27, + id: "a", + ctx: Load, + }, + ), + ), + value: NumberLiteral( + ExprNumberLiteral { + range: 29..30, value: Int( 1, ), }, ), - ), - Some( - Name( - ExprName { - range: 26..27, - id: "a", - ctx: Load, - }, - ), - ), - Some( - Name( - ExprName { - range: 32..33, - id: "b", - ctx: Load, - }, - ), - ), - ], - values: [ - NumberLiteral( - ExprNumberLiteral { - range: 23..24, - value: Int( - 2, + }, + DictItem { + key: Some( + Name( + ExprName { + range: 32..33, + id: "b", + ctx: Load, + }, ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 29..30, - value: Int( - 1, - ), - }, - ), - StringLiteral( - ExprStringLiteral { - range: 35..42, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 35..42, - value: "hello", - flags: StringLiteralFlags { - quote_style: Single, - prefix: Empty, - triple_quoted: false, + ), + value: StringLiteral( + ExprStringLiteral { + range: 35..42, + value: StringLiteralValue { + inner: Single( + StringLiteral { + range: 35..42, + value: "hello", + flags: StringLiteralFlags { + quote_style: Single, + prefix: Empty, + triple_quoted: false, + }, }, - }, - ), + ), + }, }, - }, - ), + ), + }, ], }, ), @@ -135,8 +138,7 @@ Module( value: Dict( ExprDict { range: 66..69, - keys: [], - values: [], + items: [], }, ), }, @@ -147,45 +149,47 @@ Module( value: Dict( ExprDict { range: 70..100, - keys: [ - Some( - NumberLiteral( + items: [ + DictItem { + key: Some( + NumberLiteral( + ExprNumberLiteral { + range: 76..77, + value: Int( + 1, + ), + }, + ), + ), + value: NumberLiteral( ExprNumberLiteral { - range: 76..77, + range: 83..84, value: Int( - 1, + 2, ), }, ), - ), - Some( - NumberLiteral( + }, + DictItem { + key: Some( + NumberLiteral( + ExprNumberLiteral { + range: 90..91, + value: Int( + 3, + ), + }, + ), + ), + value: NumberLiteral( ExprNumberLiteral { - range: 90..91, + range: 97..98, value: Int( - 3, + 4, ), }, ), - ), - ], - values: [ - NumberLiteral( - ExprNumberLiteral { - range: 83..84, - value: Int( - 2, - ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 97..98, - value: Int( - 4, - ), - }, - ), + }, ], }, ), @@ -197,84 +201,84 @@ Module( value: Dict( ExprDict { range: 111..132, - keys: [ - Some( - Dict( - ExprDict { - range: 112..118, - keys: [ - Some( - NumberLiteral( - ExprNumberLiteral { - range: 113..114, - value: Int( - 1, - ), - }, - ), - ), - ], - values: [ - NumberLiteral( - ExprNumberLiteral { - range: 116..117, - value: Int( - 2, - ), - }, - ), - ], - }, - ), - ), - ], - values: [ - Dict( - ExprDict { - range: 120..131, - keys: [ - Some( - NumberLiteral( - ExprNumberLiteral { - range: 121..122, - value: Int( - 3, - ), - }, - ), - ), - ], - values: [ - Dict( - ExprDict { - range: 124..130, - keys: [ - Some( + items: [ + DictItem { + key: Some( + Dict( + ExprDict { + range: 112..118, + items: [ + DictItem { + key: Some( NumberLiteral( ExprNumberLiteral { - range: 125..126, + range: 113..114, value: Int( - 4, + 1, ), }, ), ), - ], - values: [ - NumberLiteral( + value: NumberLiteral( ExprNumberLiteral { - range: 128..129, + range: 116..117, value: Int( - 5, + 2, ), }, ), - ], + }, + ], + }, + ), + ), + value: Dict( + ExprDict { + range: 120..131, + items: [ + DictItem { + key: Some( + NumberLiteral( + ExprNumberLiteral { + range: 121..122, + value: Int( + 3, + ), + }, + ), + ), + value: Dict( + ExprDict { + range: 124..130, + items: [ + DictItem { + key: Some( + NumberLiteral( + ExprNumberLiteral { + range: 125..126, + value: Int( + 4, + ), + }, + ), + ), + value: NumberLiteral( + ExprNumberLiteral { + range: 128..129, + value: Int( + 5, + ), + }, + ), + }, + ], + }, + ), }, - ), - ], - }, - ), + ], + }, + ), + }, ], }, ), @@ -286,54 +290,54 @@ Module( value: Dict( ExprDict { range: 155..171, - keys: [ - Some( - Lambda( - ExprLambda { - range: 156..167, - parameters: Some( - Parameters { - range: 163..164, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 163..164, - parameter: Parameter { + items: [ + DictItem { + key: Some( + Lambda( + ExprLambda { + range: 156..167, + parameters: Some( + Parameters { + range: 163..164, + posonlyargs: [], + args: [ + ParameterWithDefault { range: 163..164, - name: Identifier { - id: "x", + parameter: Parameter { range: 163..164, + name: Identifier { + id: "x", + range: 163..164, + }, + annotation: None, }, - annotation: None, + default: None, }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, - }, - ), - body: Name( - ExprName { - range: 166..167, - id: "x", - ctx: Load, - }, + ], + vararg: None, + kwonlyargs: [], + kwarg: None, + }, + ), + body: Name( + ExprName { + range: 166..167, + id: "x", + ctx: Load, + }, + ), + }, + ), + ), + value: NumberLiteral( + ExprNumberLiteral { + range: 169..170, + value: Int( + 1, ), }, ), - ), - ], - values: [ - NumberLiteral( - ExprNumberLiteral { - range: 169..170, - value: Int( - 1, - ), - }, - ), + }, ], }, ), @@ -345,89 +349,91 @@ Module( value: Dict( ExprDict { range: 172..202, - keys: [ - Some( - StringLiteral( - ExprStringLiteral { - range: 173..176, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 173..176, - value: "A", - flags: StringLiteralFlags { - quote_style: Single, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - ), - Some( - StringLiteral( - ExprStringLiteral { - range: 194..197, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 194..197, - value: "B", - flags: StringLiteralFlags { - quote_style: Single, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - ), - ], - values: [ - Lambda( - ExprLambda { - range: 178..192, - parameters: Some( - Parameters { - range: 185..186, - posonlyargs: [], - args: [ - ParameterWithDefault { - range: 185..186, - parameter: Parameter { - range: 185..186, - name: Identifier { - id: "p", - range: 185..186, + items: [ + DictItem { + key: Some( + StringLiteral( + ExprStringLiteral { + range: 173..176, + value: StringLiteralValue { + inner: Single( + StringLiteral { + range: 173..176, + value: "A", + flags: StringLiteralFlags { + quote_style: Single, + prefix: Empty, + triple_quoted: false, }, - annotation: None, }, - default: None, - }, - ], - vararg: None, - kwonlyargs: [], - kwarg: None, + ), + }, }, ), - body: NoneLiteral( - ExprNoneLiteral { - range: 188..192, + ), + value: Lambda( + ExprLambda { + range: 178..192, + parameters: Some( + Parameters { + range: 185..186, + posonlyargs: [], + args: [ + ParameterWithDefault { + range: 185..186, + parameter: Parameter { + range: 185..186, + name: Identifier { + id: "p", + range: 185..186, + }, + annotation: None, + }, + default: None, + }, + ], + vararg: None, + kwonlyargs: [], + kwarg: None, + }, + ), + body: NoneLiteral( + ExprNoneLiteral { + range: 188..192, + }, + ), + }, + ), + }, + DictItem { + key: Some( + StringLiteral( + ExprStringLiteral { + range: 194..197, + value: StringLiteralValue { + inner: Single( + StringLiteral { + range: 194..197, + value: "B", + flags: StringLiteralFlags { + quote_style: Single, + prefix: Empty, + triple_quoted: false, + }, + }, + ), + }, }, ), - }, - ), - Name( - ExprName { - range: 199..200, - id: "C", - ctx: Load, - }, - ), + ), + value: Name( + ExprName { + range: 199..200, + id: "C", + ctx: Load, + }, + ), + }, ], }, ), @@ -439,38 +445,38 @@ Module( value: Dict( ExprDict { range: 224..237, - keys: [ - Some( - Named( - ExprNamed { - range: 226..232, - target: Name( - ExprName { - range: 226..227, - id: "x", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 231..232, - value: Int( - 1, - ), - }, - ), + items: [ + DictItem { + key: Some( + Named( + ExprNamed { + range: 226..232, + target: Name( + ExprName { + range: 226..227, + id: "x", + ctx: Store, + }, + ), + value: NumberLiteral( + ExprNumberLiteral { + range: 231..232, + value: Int( + 1, + ), + }, + ), + }, + ), + ), + value: Name( + ExprName { + range: 235..236, + id: "y", + ctx: Load, }, ), - ), - ], - values: [ - Name( - ExprName { - range: 235..236, - id: "y", - ctx: Load, - }, - ), + }, ], }, ), @@ -482,51 +488,51 @@ Module( value: Dict( ExprDict { range: 238..258, - keys: [ - Some( - Named( + items: [ + DictItem { + key: Some( + Named( + ExprNamed { + range: 240..246, + target: Name( + ExprName { + range: 240..241, + id: "x", + ctx: Store, + }, + ), + value: NumberLiteral( + ExprNumberLiteral { + range: 245..246, + value: Int( + 1, + ), + }, + ), + }, + ), + ), + value: Named( ExprNamed { - range: 240..246, + range: 250..256, target: Name( ExprName { - range: 240..241, - id: "x", + range: 250..251, + id: "y", ctx: Store, }, ), value: NumberLiteral( ExprNumberLiteral { - range: 245..246, + range: 255..256, value: Int( - 1, + 2, ), }, ), }, ), - ), - ], - values: [ - Named( - ExprNamed { - range: 250..256, - target: Name( - ExprName { - range: 250..251, - id: "y", - ctx: Store, - }, - ), - value: NumberLiteral( - ExprNumberLiteral { - range: 255..256, - value: Int( - 2, - ), - }, - ), - }, - ), + }, ], }, ), @@ -538,17 +544,17 @@ Module( value: Dict( ExprDict { range: 284..289, - keys: [ - None, - ], - values: [ - Name( - ExprName { - range: 287..288, - id: "d", - ctx: Load, - }, - ), + items: [ + DictItem { + key: None, + value: Name( + ExprName { + range: 287..288, + id: "d", + ctx: Load, + }, + ), + }, ], }, ), @@ -560,33 +566,35 @@ Module( value: Dict( ExprDict { range: 290..301, - keys: [ - Some( - Name( + items: [ + DictItem { + key: Some( + Name( + ExprName { + range: 291..292, + id: "a", + ctx: Load, + }, + ), + ), + value: Name( ExprName { - range: 291..292, - id: "a", + range: 294..295, + id: "b", ctx: Load, }, ), - ), - None, - ], - values: [ - Name( - ExprName { - range: 294..295, - id: "b", - ctx: Load, - }, - ), - Name( - ExprName { - range: 299..300, - id: "d", - ctx: Load, - }, - ), + }, + DictItem { + key: None, + value: Name( + ExprName { + range: 299..300, + id: "d", + ctx: Load, + }, + ), + }, ], }, ), @@ -598,25 +606,27 @@ Module( value: Dict( ExprDict { range: 302..312, - keys: [ - None, - None, - ], - values: [ - Name( - ExprName { - range: 305..306, - id: "a", - ctx: Load, - }, - ), - Name( - ExprName { - range: 310..311, - id: "b", - ctx: Load, - }, - ), + items: [ + DictItem { + key: None, + value: Name( + ExprName { + range: 305..306, + id: "a", + ctx: Load, + }, + ), + }, + DictItem { + key: None, + value: Name( + ExprName { + range: 310..311, + id: "b", + ctx: Load, + }, + ), + }, ], }, ), @@ -628,16 +638,36 @@ Module( value: Dict( ExprDict { range: 313..338, - keys: [ - Some( - StringLiteral( + items: [ + DictItem { + key: Some( + StringLiteral( + ExprStringLiteral { + range: 314..317, + value: StringLiteralValue { + inner: Single( + StringLiteral { + range: 314..317, + value: "a", + flags: StringLiteralFlags { + quote_style: Double, + prefix: Empty, + triple_quoted: false, + }, + }, + ), + }, + }, + ), + ), + value: StringLiteral( ExprStringLiteral { - range: 314..317, + range: 319..322, value: StringLiteralValue { inner: Single( StringLiteral { - range: 314..317, - value: "a", + range: 319..322, + value: "b", flags: StringLiteralFlags { quote_style: Double, prefix: Empty, @@ -648,17 +678,46 @@ Module( }, }, ), - ), - None, - Some( - StringLiteral( + }, + DictItem { + key: None, + value: Name( + ExprName { + range: 326..327, + id: "c", + ctx: Load, + }, + ), + }, + DictItem { + key: Some( + StringLiteral( + ExprStringLiteral { + range: 329..332, + value: StringLiteralValue { + inner: Single( + StringLiteral { + range: 329..332, + value: "d", + flags: StringLiteralFlags { + quote_style: Double, + prefix: Empty, + triple_quoted: false, + }, + }, + ), + }, + }, + ), + ), + value: StringLiteral( ExprStringLiteral { - range: 329..332, + range: 334..337, value: StringLiteralValue { inner: Single( StringLiteral { - range: 329..332, - value: "d", + range: 334..337, + value: "e", flags: StringLiteralFlags { quote_style: Double, prefix: Empty, @@ -669,52 +728,7 @@ Module( }, }, ), - ), - ], - values: [ - StringLiteral( - ExprStringLiteral { - range: 319..322, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 319..322, - value: "b", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - Name( - ExprName { - range: 326..327, - id: "c", - ctx: Load, - }, - ), - StringLiteral( - ExprStringLiteral { - range: 334..337, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 334..337, - value: "e", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), + }, ], }, ), @@ -726,75 +740,77 @@ Module( value: Dict( ExprDict { range: 339..367, - keys: [ - Some( - NumberLiteral( + items: [ + DictItem { + key: Some( + NumberLiteral( + ExprNumberLiteral { + range: 340..341, + value: Int( + 1, + ), + }, + ), + ), + value: NumberLiteral( ExprNumberLiteral { - range: 340..341, + range: 343..344, value: Int( - 1, + 2, ), }, ), - ), - None, - ], - values: [ - NumberLiteral( - ExprNumberLiteral { - range: 343..344, - value: Int( - 2, - ), - }, - ), - Dict( - ExprDict { - range: 348..366, - keys: [ - Some( - StringLiteral( - ExprStringLiteral { - range: 349..357, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 349..357, - value: "nested", - flags: StringLiteralFlags { - quote_style: Single, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), - ), - ], - values: [ - StringLiteral( - ExprStringLiteral { - range: 359..365, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 359..365, - value: "dict", - flags: StringLiteralFlags { - quote_style: Single, - prefix: Empty, - triple_quoted: false, + }, + DictItem { + key: None, + value: Dict( + ExprDict { + range: 348..366, + items: [ + DictItem { + key: Some( + StringLiteral( + ExprStringLiteral { + range: 349..357, + value: StringLiteralValue { + inner: Single( + StringLiteral { + range: 349..357, + value: "nested", + flags: StringLiteralFlags { + quote_style: Single, + prefix: Empty, + triple_quoted: false, + }, + }, + ), }, }, ), - }, + ), + value: StringLiteral( + ExprStringLiteral { + range: 359..365, + value: StringLiteralValue { + inner: Single( + StringLiteral { + range: 359..365, + value: "dict", + flags: StringLiteralFlags { + quote_style: Single, + prefix: Empty, + triple_quoted: false, + }, + }, + ), + }, + }, + ), }, - ), - ], - }, - ), + ], + }, + ), + }, ], }, ), @@ -806,71 +822,73 @@ Module( value: Dict( ExprDict { range: 368..393, - keys: [ - Some( - BinOp( + items: [ + DictItem { + key: Some( + BinOp( + ExprBinOp { + range: 369..374, + left: Name( + ExprName { + range: 369..370, + id: "x", + ctx: Load, + }, + ), + op: Mult, + right: NumberLiteral( + ExprNumberLiteral { + range: 373..374, + value: Int( + 1, + ), + }, + ), + }, + ), + ), + value: BinOp( ExprBinOp { - range: 369..374, + range: 376..382, left: Name( ExprName { - range: 369..370, - id: "x", + range: 376..377, + id: "y", ctx: Load, }, ), - op: Mult, + op: Pow, right: NumberLiteral( ExprNumberLiteral { - range: 373..374, + range: 381..382, value: Int( - 1, + 2, ), }, ), }, ), - ), - None, - ], - values: [ - BinOp( - ExprBinOp { - range: 376..382, - left: Name( - ExprName { - range: 376..377, - id: "y", - ctx: Load, + }, + DictItem { + key: None, + value: Call( + ExprCall { + range: 386..392, + func: Name( + ExprName { + range: 386..390, + id: "call", + ctx: Load, + }, + ), + arguments: Arguments { + range: 390..392, + args: [], + keywords: [], }, - ), - op: Pow, - right: NumberLiteral( - ExprNumberLiteral { - range: 381..382, - value: Int( - 2, - ), - }, - ), - }, - ), - Call( - ExprCall { - range: 386..392, - func: Name( - ExprName { - range: 386..390, - id: "call", - ctx: Load, - }, - ), - arguments: Arguments { - range: 390..392, - args: [], - keywords: [], }, - }, - ), + ), + }, ], }, ), @@ -882,23 +900,23 @@ Module( value: Dict( ExprDict { range: 460..471, - keys: [ - None, - ], - values: [ - UnaryOp( - ExprUnaryOp { - range: 464..469, - op: Not, - operand: Name( - ExprName { - range: 468..469, - id: "x", - ctx: Load, - }, - ), - }, - ), + items: [ + DictItem { + key: None, + value: UnaryOp( + ExprUnaryOp { + range: 464..469, + op: Not, + operand: Name( + ExprName { + range: 468..469, + id: "x", + ctx: Load, + }, + ), + }, + ), + }, ], }, ), @@ -910,44 +928,44 @@ Module( value: Dict( ExprDict { range: 494..515, - keys: [ - Some( - NumberLiteral( - ExprNumberLiteral { - range: 495..496, - value: Int( - 1, + items: [ + DictItem { + key: Some( + NumberLiteral( + ExprNumberLiteral { + range: 495..496, + value: Int( + 1, + ), + }, + ), + ), + value: If( + ExprIf { + range: 498..514, + test: BooleanLiteral( + ExprBooleanLiteral { + range: 503..507, + value: true, + }, + ), + body: Name( + ExprName { + range: 498..499, + id: "x", + ctx: Load, + }, + ), + orelse: Name( + ExprName { + range: 513..514, + id: "y", + ctx: Load, + }, ), }, ), - ), - ], - values: [ - If( - ExprIf { - range: 498..514, - test: BooleanLiteral( - ExprBooleanLiteral { - range: 503..507, - value: true, - }, - ), - body: Name( - ExprName { - range: 498..499, - id: "x", - ctx: Load, - }, - ), - orelse: Name( - ExprName { - range: 513..514, - id: "y", - ctx: Load, - }, - ), - }, - ), + }, ], }, ), @@ -1079,78 +1097,80 @@ Module( value: Dict( ExprDict { range: 576..600, - keys: [ - Some( - Set( - ExprSet { - range: 577..583, - elts: [ - NumberLiteral( - ExprNumberLiteral { - range: 578..579, - value: Int( - 1, + items: [ + DictItem { + key: Some( + Set( + ExprSet { + range: 577..583, + elts: [ + NumberLiteral( + ExprNumberLiteral { + range: 578..579, + value: Int( + 1, + ), + }, + ), + NumberLiteral( + ExprNumberLiteral { + range: 581..582, + value: Int( + 2, + ), + }, + ), + ], + }, + ), + ), + value: NumberLiteral( + ExprNumberLiteral { + range: 585..586, + value: Int( + 3, + ), + }, + ), + }, + DictItem { + key: Some( + Name( + ExprName { + range: 588..589, + id: "x", + ctx: Load, + }, + ), + ), + value: Dict( + ExprDict { + range: 591..598, + items: [ + DictItem { + key: Some( + NumberLiteral( + ExprNumberLiteral { + range: 592..593, + value: Int( + 1, + ), + }, ), - }, - ), - NumberLiteral( - ExprNumberLiteral { - range: 581..582, - value: Int( - 2, - ), - }, - ), + ), + value: NumberLiteral( + ExprNumberLiteral { + range: 595..596, + value: Int( + 2, + ), + }, + ), + }, ], }, ), - ), - Some( - Name( - ExprName { - range: 588..589, - id: "x", - ctx: Load, - }, - ), - ), - ], - values: [ - NumberLiteral( - ExprNumberLiteral { - range: 585..586, - value: Int( - 3, - ), - }, - ), - Dict( - ExprDict { - range: 591..598, - keys: [ - Some( - NumberLiteral( - ExprNumberLiteral { - range: 592..593, - value: Int( - 1, - ), - }, - ), - ), - ], - values: [ - NumberLiteral( - ExprNumberLiteral { - range: 595..596, - value: Int( - 2, - ), - }, - ), - ], - }, - ), + }, ], }, ), @@ -1162,41 +1182,43 @@ Module( value: Dict( ExprDict { range: 601..621, - keys: [ - Some( - Name( + items: [ + DictItem { + key: Some( + Name( + ExprName { + range: 603..604, + id: "x", + ctx: Load, + }, + ), + ), + value: Name( ExprName { - range: 603..604, - id: "x", + range: 608..609, + id: "y", ctx: Load, }, ), - ), - Some( - Name( + }, + DictItem { + key: Some( + Name( + ExprName { + range: 613..614, + id: "z", + ctx: Load, + }, + ), + ), + value: Name( ExprName { - range: 613..614, - id: "z", + range: 618..619, + id: "a", ctx: Load, }, ), - ), - ], - values: [ - Name( - ExprName { - range: 608..609, - id: "y", - ctx: Load, - }, - ), - Name( - ExprName { - range: 618..619, - id: "a", - ctx: Load, - }, - ), + }, ], }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__f_string.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__f_string.py.snap index 4f94e70796..cc523d29a6 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__f_string.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__f_string.py.snap @@ -823,104 +823,104 @@ Module( value: Dict( ExprDict { range: 219..253, - keys: [ - Some( - FString( - ExprFString { - range: 220..248, - value: FStringValue { - inner: Concatenated( - [ - Literal( - StringLiteral { - range: 220..226, - value: "foo ", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, + items: [ + DictItem { + key: Some( + FString( + ExprFString { + range: 220..248, + value: FStringValue { + inner: Concatenated( + [ + Literal( + StringLiteral { + range: 220..226, + value: "foo ", + flags: StringLiteralFlags { + quote_style: Double, + prefix: Empty, + triple_quoted: false, + }, }, - }, - ), - FString( - FString { - range: 227..242, - elements: [ - Literal( - FStringLiteralElement { - range: 229..233, - value: "bar ", - }, - ), - Expression( - FStringExpressionElement { - range: 233..240, - expression: BinOp( - ExprBinOp { - range: 234..239, - left: Name( - ExprName { - range: 234..235, - id: "x", - ctx: Load, - }, - ), - op: Add, - right: Name( - ExprName { - range: 238..239, - id: "y", - ctx: Load, - }, - ), - }, - ), - debug_text: None, - conversion: None, - format_spec: None, - }, - ), - Literal( - FStringLiteralElement { - range: 240..241, - value: " ", - }, - ), - ], - flags: FStringFlags { - quote_style: Double, - prefix: Regular, - triple_quoted: false, + ), + FString( + FString { + range: 227..242, + elements: [ + Literal( + FStringLiteralElement { + range: 229..233, + value: "bar ", + }, + ), + Expression( + FStringExpressionElement { + range: 233..240, + expression: BinOp( + ExprBinOp { + range: 234..239, + left: Name( + ExprName { + range: 234..235, + id: "x", + ctx: Load, + }, + ), + op: Add, + right: Name( + ExprName { + range: 238..239, + id: "y", + ctx: Load, + }, + ), + }, + ), + debug_text: None, + conversion: None, + format_spec: None, + }, + ), + Literal( + FStringLiteralElement { + range: 240..241, + value: " ", + }, + ), + ], + flags: FStringFlags { + quote_style: Double, + prefix: Regular, + triple_quoted: false, + }, }, - }, - ), - Literal( - StringLiteral { - range: 243..248, - value: "baz", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, + ), + Literal( + StringLiteral { + range: 243..248, + value: "baz", + flags: StringLiteralFlags { + quote_style: Double, + prefix: Empty, + triple_quoted: false, + }, }, - }, - ), - ], - ), + ), + ], + ), + }, }, + ), + ), + value: NumberLiteral( + ExprNumberLiteral { + range: 250..252, + value: Int( + 10, + ), }, ), - ), - ], - values: [ - NumberLiteral( - ExprNumberLiteral { - range: 250..252, - value: Int( - 10, - ), - }, - ), + }, ], }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__list.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__list.py.snap index 8d9b4f8292..ede492d09f 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__list.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__list.py.snap @@ -652,26 +652,26 @@ Module( Dict( ExprDict { range: 319..325, - keys: [ - Some( - Name( - ExprName { - range: 320..321, - id: "a", - ctx: Load, + items: [ + DictItem { + key: Some( + Name( + ExprName { + range: 320..321, + id: "a", + ctx: Load, + }, + ), + ), + value: NumberLiteral( + ExprNumberLiteral { + range: 323..324, + value: Int( + 1, + ), }, ), - ), - ], - values: [ - NumberLiteral( - ExprNumberLiteral { - range: 323..324, - value: Int( - 1, - ), - }, - ), + }, ], }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__set.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__set.py.snap index a607c403b1..38620ecf79 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__set.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__set.py.snap @@ -15,8 +15,7 @@ Module( value: Dict( ExprDict { range: 14..16, - keys: [], - values: [], + items: [], }, ), }, @@ -139,8 +138,7 @@ Module( value: Dict( ExprDict { range: 74..77, - keys: [], - values: [], + items: [], }, ), }, @@ -579,33 +577,35 @@ Module( Dict( ExprDict { range: 300..311, - keys: [ - Some( - Name( + items: [ + DictItem { + key: Some( + Name( + ExprName { + range: 301..302, + id: "a", + ctx: Load, + }, + ), + ), + value: Name( ExprName { - range: 301..302, - id: "a", + range: 304..305, + id: "b", ctx: Load, }, ), - ), - None, - ], - values: [ - Name( - ExprName { - range: 304..305, - id: "b", - ctx: Load, - }, - ), - Name( - ExprName { - range: 309..310, - id: "d", - ctx: Load, - }, - ), + }, + DictItem { + key: None, + value: Name( + ExprName { + range: 309..310, + id: "d", + ctx: Load, + }, + ), + }, ], }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__yield.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__yield.py.snap index d65f741b01..8eda1ccf60 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__yield.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__yield.py.snap @@ -216,26 +216,26 @@ Module( Dict( ExprDict { range: 85..91, - keys: [ - Some( - Name( - ExprName { - range: 86..87, - id: "x", - ctx: Load, + items: [ + DictItem { + key: Some( + Name( + ExprName { + range: 86..87, + id: "x", + ctx: Load, + }, + ), + ), + value: NumberLiteral( + ExprNumberLiteral { + range: 89..90, + value: Int( + 5, + ), }, ), - ), - ], - values: [ - NumberLiteral( - ExprNumberLiteral { - range: 89..90, - value: Int( - 5, - ), - }, - ), + }, ], }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__yield_from.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__yield_from.py.snap index fe161c3851..d069483300 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__yield_from.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__yield_from.py.snap @@ -192,26 +192,26 @@ Module( value: Dict( ExprDict { range: 114..120, - keys: [ - Some( - Name( - ExprName { - range: 115..116, - id: "x", - ctx: Load, + items: [ + DictItem { + key: Some( + Name( + ExprName { + range: 115..116, + id: "x", + ctx: Load, + }, + ), + ), + value: NumberLiteral( + ExprNumberLiteral { + range: 118..119, + value: Int( + 5, + ), }, ), - ), - ], - values: [ - NumberLiteral( - ExprNumberLiteral { - range: 118..119, - value: Int( - 5, - ), - }, - ), + }, ], }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__match.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__match.py.snap index 1b25503682..c28a10dae8 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__match.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__match.py.snap @@ -3814,37 +3814,37 @@ Module( subject: Dict( ExprDict { range: 2959..2970, - keys: [ - Some( - StringLiteral( - ExprStringLiteral { - range: 2960..2966, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 2960..2966, - value: "test", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, + items: [ + DictItem { + key: Some( + StringLiteral( + ExprStringLiteral { + range: 2960..2966, + value: StringLiteralValue { + inner: Single( + StringLiteral { + range: 2960..2966, + value: "test", + flags: StringLiteralFlags { + quote_style: Double, + prefix: Empty, + triple_quoted: false, + }, }, - }, - ), + ), + }, }, + ), + ), + value: NumberLiteral( + ExprNumberLiteral { + range: 2968..2969, + value: Int( + 1, + ), }, ), - ), - ], - values: [ - NumberLiteral( - ExprNumberLiteral { - range: 2968..2969, - value: Int( - 1, - ), - }, - ), + }, ], }, ), @@ -3907,16 +3907,36 @@ Module( subject: Dict( ExprDict { range: 3032..3049, - keys: [ - Some( - StringLiteral( + items: [ + DictItem { + key: Some( + StringLiteral( + ExprStringLiteral { + range: 3033..3040, + value: StringLiteralValue { + inner: Single( + StringLiteral { + range: 3033..3040, + value: "label", + flags: StringLiteralFlags { + quote_style: Double, + prefix: Empty, + triple_quoted: false, + }, + }, + ), + }, + }, + ), + ), + value: StringLiteral( ExprStringLiteral { - range: 3033..3040, + range: 3042..3048, value: StringLiteralValue { inner: Single( StringLiteral { - range: 3033..3040, - value: "label", + range: 3042..3048, + value: "test", flags: StringLiteralFlags { quote_style: Double, prefix: Empty, @@ -3927,27 +3947,7 @@ Module( }, }, ), - ), - ], - values: [ - StringLiteral( - ExprStringLiteral { - range: 3042..3048, - value: StringLiteralValue { - inner: Single( - StringLiteral { - range: 3042..3048, - value: "test", - flags: StringLiteralFlags { - quote_style: Double, - prefix: Empty, - triple_quoted: false, - }, - }, - ), - }, - }, - ), + }, ], }, ),