Refactor the ExprDict node (#11267)

Co-authored-by: Micha Reiser <micha@reiser.io>
This commit is contained in:
Alex Waygood 2024-05-07 12:46:10 +01:00 committed by GitHub
parent de270154a1
commit 6774f27f4b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
52 changed files with 2425 additions and 2240 deletions

View file

@ -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() {
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);
}
for value in values {
self.visit_type_definition(value);
}
} else {

View file

@ -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;
}
}

View file

@ -89,20 +89,21 @@ 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()) {
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(attr.to_string()),
key.range(),
LoggingExtraAttrClash(invalid_key.value.to_string()),
invalid_key.range(),
));
}
}
}
}
}
Expr::Call(ast::ExprCall {
func,
arguments: Arguments { keywords, .. },

View file

@ -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());

View file

@ -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::<Vec<_>>();
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);
}

View file

@ -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() {

View file

@ -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 {

View file

@ -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

View file

@ -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<ComparableExpr, FxHashSet<ComparableExpr>> =
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(),
)));
}

View file

@ -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());

View file

@ -170,16 +170,12 @@ fn is_valid_tuple(formats: &[CFormatStrOrBytes<String>], elts: &[Expr]) -> bool
}
/// Return `true` if the dictionary values align with the format types.
fn is_valid_dict(
formats: &[CFormatStrOrBytes<String>],
keys: &[Option<Expr>],
values: &[Expr],
) -> bool {
fn is_valid_dict(formats: &[CFormatStrOrBytes<String>], 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 {

View file

@ -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
})

View file

@ -229,7 +229,7 @@ fn slots_attributes(expr: &Expr) -> impl Iterator<Item = &str> {
// 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,
})),

View file

@ -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(

View file

@ -163,16 +163,16 @@ fn create_class_def_stmt(
.into()
}
fn fields_from_dict_literal(keys: &[Option<Expr>], values: &[Expr]) -> Option<Vec<Stmt>> {
if keys.is_empty() {
fn fields_from_dict_literal(items: &[ast::DictItem]) -> Option<Vec<Stmt>> {
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<Stmt>, 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, .. },

View file

@ -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<String> {
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<String> = 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 {

View file

@ -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<Fix> {
fn generate_fix(&self, elements: &[&str], checker: &Checker) -> Option<Fix> {
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()`

View file

@ -687,10 +687,24 @@ pub struct ExprIf<'a> {
orelse: Box<ComparableExpr<'a>>,
}
#[derive(Debug, PartialEq, Eq, Hash)]
pub struct ComparableDictItem<'a> {
key: Option<ComparableExpr<'a>>,
value: ComparableExpr<'a>,
}
impl<'a> From<&'a ast::DictItem> for ComparableDictItem<'a> {
fn from(ast::DictItem { key, value }: &'a ast::DictItem) -> Self {
Self {
key: key.as_ref().map(ComparableExpr::from),
value: value.into(),
}
}
}
#[derive(Debug, PartialEq, Eq, Hash)]
pub struct ExprDict<'a> {
keys: Vec<Option<ComparableExpr<'a>>>,
values: Vec<ComparableExpr<'a>>,
items: Vec<ComparableDictItem<'a>>,
}
#[derive(Debug, PartialEq, Eq, Hash)]
@ -933,16 +947,8 @@ impl<'a> From<&'a ast::Expr> for ComparableExpr<'a> {
body: body.into(),
orelse: orelse.into(),
}),
ast::Expr::Dict(ast::ExprDict {
keys,
values,
range: _,
}) => Self::Dict(ExprDict {
keys: keys
.iter()
.map(|expr| expr.as_ref().map(Into::into))
.collect(),
values: values.iter().map(Into::into).collect(),
ast::Expr::Dict(ast::ExprDict { items, range: _ }) => Self::Dict(ExprDict {
items: items.iter().map(ComparableDictItem::from).collect(),
}),
ast::Expr::Set(ast::ExprSet { elts, range: _ }) => Self::Set(ExprSet {
elts: elts.iter().map(Into::into).collect(),

View file

@ -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

View file

@ -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);
}

View file

@ -767,12 +767,89 @@ impl From<ExprIf> 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<Expr>,
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<Option<Expr>>,
pub values: Vec<Expr>,
pub items: Vec<DictItem>,
}
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<ExprDict> for Expr {
@ -781,6 +858,90 @@ impl From<ExprDict> 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::Item> {
self.items.next().map(DictItem::key)
}
fn last(mut self) -> Option<Self::Item> {
self.next_back()
}
fn size_hint(&self) -> (usize, Option<usize>) {
self.items.size_hint()
}
}
impl<'a> DoubleEndedIterator for DictKeyIterator<'a> {
fn next_back(&mut self) -> Option<Self::Item> {
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::Item> {
self.items.next().map(DictItem::value)
}
fn last(mut self) -> Option<Self::Item> {
self.next_back()
}
fn size_hint(&self) -> (usize, Option<usize>) {
self.items.size_hint()
}
}
impl<'a> DoubleEndedIterator for DictValueIterator<'a> {
fn next_back(&mut self) -> Option<Self::Item> {
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::<ExprBytesLiteral>(), 40);
assert_eq!(std::mem::size_of::<ExprCall>(), 56);
assert_eq!(std::mem::size_of::<ExprCompare>(), 48);
assert_eq!(std::mem::size_of::<ExprDict>(), 56);
assert_eq!(std::mem::size_of::<ExprDict>(), 32);
assert_eq!(std::mem::size_of::<ExprDictComp>(), 48);
assert_eq!(std::mem::size_of::<ExprEllipsisLiteral>(), 8);
// 56 for Rustc < 1.76

View file

@ -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);
Expr::Dict(ast::ExprDict { items, range: _ }) => {
for ast::DictItem { key, value } in items {
if let Some(key) = key {
visitor.visit_expr(key);
}
for expr in values {
visitor.visit_expr(expr);
visitor.visit_expr(value);
}
}
Expr::Set(ast::ExprSet { elts, range: _ }) => {

View file

@ -376,16 +376,12 @@ pub fn walk_expr<V: Transformer + ?Sized>(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);
Expr::Dict(ast::ExprDict { items, range: _ }) => {
for ast::DictItem { key, value } in items {
if let Some(key) = key {
visitor.visit_expr(key);
}
for expr in values {
visitor.visit_expr(expr);
visitor.visit_expr(value);
}
}
Expr::Set(ast::ExprSet { elts, range: _ }) => {

View file

@ -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("}");

View file

@ -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<ExprDict> 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<ExprDict> 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<Expr>, value: &'a Expr) -> Self {
fn new(item: &'a DictItem) -> Self {
Self {
key,
value,
key: &item.key,
value: &item.value,
comments: &[],
}
}

View file

@ -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(),

View file

@ -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,
}
}

View file

@ -51,24 +51,23 @@ pub(super) fn pattern_to_expr(pattern: Pattern) -> Expr {
patterns,
rest,
}) => {
let mut keys = keys.into_iter().map(Option::Some).collect::<Vec<_>>();
let mut values = patterns
let mut items: Vec<ast::DictItem> = keys
.into_iter()
.map(pattern_to_expr)
.collect::<Vec<_>>();
.zip(patterns)
.map(|(key, pattern)| ast::DictItem {
key: Some(key),
value: pattern_to_expr(pattern),
})
.collect();
if let Some(rest) = rest {
keys.push(None);
values.push(Expr::Name(ast::ExprName {
let value = Expr::Name(ast::ExprName {
range: rest.range,
id: rest.id,
ctx: ExprContext::Store,
}));
});
items.push(ast::DictItem { key: None, value });
}
Expr::Dict(ast::ExprDict {
range,
keys,
values,
})
Expr::Dict(ast::ExprDict { range, items })
}
Pattern::MatchClass(ast::PatternMatchClass {
range,

View file

@ -15,9 +15,19 @@ Module(
value: Dict(
ExprDict {
range: 125..135,
keys: [
None,
Some(
items: [
DictItem {
key: None,
value: Name(
ExprName {
range: 128..129,
id: "x",
ctx: Load,
},
),
},
DictItem {
key: Some(
NumberLiteral(
ExprNumberLiteral {
range: 133..134,
@ -27,22 +37,14 @@ Module(
},
),
),
],
values: [
Name(
ExprName {
range: 128..129,
id: "x",
ctx: Load,
},
),
Name(
value: Name(
ExprName {
range: 134..134,
id: "",
ctx: Invalid,
},
),
},
],
},
),
@ -54,8 +56,9 @@ Module(
value: Dict(
ExprDict {
range: 136..162,
keys: [
Some(
items: [
DictItem {
key: Some(
Name(
ExprName {
range: 137..138,
@ -64,10 +67,7 @@ Module(
},
),
),
None,
],
values: [
NumberLiteral(
value: NumberLiteral(
ExprNumberLiteral {
range: 140..141,
value: Int(
@ -75,7 +75,10 @@ Module(
),
},
),
If(
},
DictItem {
key: None,
value: If(
ExprIf {
range: 145..161,
test: BooleanLiteral(
@ -100,6 +103,7 @@ Module(
),
},
),
},
],
},
),
@ -111,20 +115,10 @@ Module(
value: Dict(
ExprDict {
range: 163..184,
keys: [
None,
Some(
Name(
ExprName {
range: 179..180,
id: "b",
ctx: Load,
},
),
),
],
values: [
Lambda(
items: [
DictItem {
key: None,
value: Lambda(
ExprLambda {
range: 166..177,
parameters: Some(
@ -159,7 +153,18 @@ Module(
),
},
),
NumberLiteral(
},
DictItem {
key: Some(
Name(
ExprName {
range: 179..180,
id: "b",
ctx: Load,
},
),
),
value: NumberLiteral(
ExprNumberLiteral {
range: 182..183,
value: Int(
@ -167,6 +172,7 @@ Module(
),
},
),
},
],
},
),
@ -178,8 +184,9 @@ Module(
value: Dict(
ExprDict {
range: 185..201,
keys: [
Some(
items: [
DictItem {
key: Some(
Name(
ExprName {
range: 186..187,
@ -188,10 +195,7 @@ Module(
},
),
),
None,
],
values: [
NumberLiteral(
value: NumberLiteral(
ExprNumberLiteral {
range: 189..190,
value: Int(
@ -199,7 +203,10 @@ Module(
),
},
),
BoolOp(
},
DictItem {
key: None,
value: BoolOp(
ExprBoolOp {
range: 194..200,
op: Or,
@ -221,6 +228,7 @@ Module(
],
},
),
},
],
},
),
@ -232,20 +240,10 @@ Module(
value: Dict(
ExprDict {
range: 202..219,
keys: [
None,
Some(
Name(
ExprName {
range: 214..215,
id: "b",
ctx: Load,
},
),
),
],
values: [
BoolOp(
items: [
DictItem {
key: None,
value: BoolOp(
ExprBoolOp {
range: 205..212,
op: And,
@ -267,7 +265,18 @@ Module(
],
},
),
NumberLiteral(
},
DictItem {
key: Some(
Name(
ExprName {
range: 214..215,
id: "b",
ctx: Load,
},
),
),
value: NumberLiteral(
ExprNumberLiteral {
range: 217..218,
value: Int(
@ -275,6 +284,7 @@ Module(
),
},
),
},
],
},
),
@ -286,8 +296,9 @@ Module(
value: Dict(
ExprDict {
range: 220..241,
keys: [
Some(
items: [
DictItem {
key: Some(
Name(
ExprName {
range: 221..222,
@ -296,19 +307,7 @@ Module(
},
),
),
None,
Some(
Name(
ExprName {
range: 236..237,
id: "b",
ctx: Load,
},
),
),
],
values: [
NumberLiteral(
value: NumberLiteral(
ExprNumberLiteral {
range: 224..225,
value: Int(
@ -316,7 +315,10 @@ Module(
),
},
),
UnaryOp(
},
DictItem {
key: None,
value: UnaryOp(
ExprUnaryOp {
range: 229..234,
op: Not,
@ -329,7 +331,18 @@ Module(
),
},
),
NumberLiteral(
},
DictItem {
key: Some(
Name(
ExprName {
range: 236..237,
id: "b",
ctx: Load,
},
),
),
value: NumberLiteral(
ExprNumberLiteral {
range: 239..240,
value: Int(
@ -337,6 +350,7 @@ Module(
),
},
),
},
],
},
),
@ -348,11 +362,10 @@ Module(
value: Dict(
ExprDict {
range: 242..252,
keys: [
None,
],
values: [
Compare(
items: [
DictItem {
key: None,
value: Compare(
ExprCompare {
range: 245..251,
left: Name(
@ -376,6 +389,7 @@ Module(
],
},
),
},
],
},
),
@ -387,11 +401,10 @@ Module(
value: Dict(
ExprDict {
range: 253..267,
keys: [
None,
],
values: [
Compare(
items: [
DictItem {
key: None,
value: Compare(
ExprCompare {
range: 256..266,
left: Name(
@ -415,6 +428,7 @@ Module(
],
},
),
},
],
},
),
@ -426,11 +440,10 @@ Module(
value: Dict(
ExprDict {
range: 268..277,
keys: [
None,
],
values: [
Compare(
items: [
DictItem {
key: None,
value: Compare(
ExprCompare {
range: 271..276,
left: Name(
@ -454,6 +467,7 @@ Module(
],
},
),
},
],
},
),

View file

@ -15,9 +15,19 @@ Module(
value: Dict(
ExprDict {
range: 122..147,
keys: [
None,
Some(
items: [
DictItem {
key: None,
value: Name(
ExprName {
range: 125..126,
id: "x",
ctx: Load,
},
),
},
DictItem {
key: Some(
Name(
ExprName {
range: 128..129,
@ -26,7 +36,16 @@ Module(
},
),
),
Some(
value: Name(
ExprName {
range: 130..133,
id: "for",
ctx: Load,
},
),
},
DictItem {
key: Some(
Name(
ExprName {
range: 134..135,
@ -35,7 +54,16 @@ Module(
},
),
),
Some(
value: Name(
ExprName {
range: 135..135,
id: "",
ctx: Invalid,
},
),
},
DictItem {
key: Some(
Compare(
ExprCompare {
range: 137..146,
@ -61,36 +89,14 @@ Module(
},
),
),
],
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(
value: Name(
ExprName {
range: 146..146,
id: "",
ctx: Invalid,
},
),
},
],
},
),

View file

@ -15,8 +15,9 @@ Module(
value: Dict(
ExprDict {
range: 0..24,
keys: [
Some(
items: [
DictItem {
key: Some(
Name(
ExprName {
range: 1..2,
@ -25,7 +26,16 @@ Module(
},
),
),
Some(
value: Name(
ExprName {
range: 5..8,
id: "def",
ctx: Load,
},
),
},
DictItem {
key: Some(
Call(
ExprCall {
range: 9..14,
@ -44,22 +54,14 @@ Module(
},
),
),
],
values: [
Name(
ExprName {
range: 5..8,
id: "def",
ctx: Load,
},
),
Name(
value: Name(
ExprName {
range: 20..24,
id: "pass",
ctx: Load,
},
),
},
],
},
),

View file

@ -15,8 +15,9 @@ Module(
value: Dict(
ExprDict {
range: 0..10,
keys: [
Some(
items: [
DictItem {
key: Some(
Name(
ExprName {
range: 1..2,
@ -25,9 +26,7 @@ Module(
},
),
),
],
values: [
BinOp(
value: BinOp(
ExprBinOp {
range: 5..10,
left: NumberLiteral(
@ -49,6 +48,7 @@ Module(
),
},
),
},
],
},
),

View file

@ -15,8 +15,9 @@ Module(
value: Dict(
ExprDict {
range: 0..6,
keys: [
Some(
items: [
DictItem {
key: Some(
Name(
ExprName {
range: 1..2,
@ -25,9 +26,7 @@ Module(
},
),
),
],
values: [
NumberLiteral(
value: NumberLiteral(
ExprNumberLiteral {
range: 4..5,
value: Int(
@ -35,6 +34,7 @@ Module(
),
},
),
},
],
},
),

View file

@ -15,8 +15,9 @@ Module(
value: Dict(
ExprDict {
range: 55..77,
keys: [
Some(
items: [
DictItem {
key: Some(
Named(
ExprNamed {
range: 56..62,
@ -38,7 +39,16 @@ Module(
},
),
),
Some(
value: Name(
ExprName {
range: 64..65,
id: "y",
ctx: Load,
},
),
},
DictItem {
key: Some(
Name(
ExprName {
range: 67..68,
@ -47,7 +57,16 @@ Module(
},
),
),
Some(
value: Name(
ExprName {
range: 68..68,
id: "",
ctx: Invalid,
},
),
},
DictItem {
key: Some(
NumberLiteral(
ExprNumberLiteral {
range: 72..73,
@ -57,29 +76,14 @@ Module(
},
),
),
],
values: [
Name(
ExprName {
range: 64..65,
id: "y",
ctx: Load,
},
),
Name(
ExprName {
range: 68..68,
id: "",
ctx: Invalid,
},
),
Name(
value: Name(
ExprName {
range: 75..76,
id: "a",
ctx: Load,
},
),
},
],
},
),

View file

@ -15,8 +15,9 @@ Module(
value: Dict(
ExprDict {
range: 57..79,
keys: [
Some(
items: [
DictItem {
key: Some(
Name(
ExprName {
range: 58..59,
@ -25,7 +26,16 @@ Module(
},
),
),
Some(
value: Name(
ExprName {
range: 61..62,
id: "y",
ctx: Load,
},
),
},
DictItem {
key: Some(
NumberLiteral(
ExprNumberLiteral {
range: 66..67,
@ -35,7 +45,16 @@ Module(
},
),
),
Some(
value: Name(
ExprName {
range: 67..67,
id: "",
ctx: Invalid,
},
),
},
DictItem {
key: Some(
Name(
ExprName {
range: 69..70,
@ -44,7 +63,16 @@ Module(
},
),
),
Some(
value: Name(
ExprName {
range: 72..73,
id: "a",
ctx: Load,
},
),
},
DictItem {
key: Some(
NumberLiteral(
ExprNumberLiteral {
range: 77..78,
@ -54,36 +82,14 @@ Module(
},
),
),
],
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(
value: Name(
ExprName {
range: 78..78,
id: "",
ctx: Invalid,
},
),
},
],
},
),

View file

@ -34,8 +34,9 @@ Module(
value: Dict(
ExprDict {
range: 93..105,
keys: [
Some(
items: [
DictItem {
key: Some(
NumberLiteral(
ExprNumberLiteral {
range: 94..95,
@ -45,7 +46,17 @@ Module(
},
),
),
Some(
value: NumberLiteral(
ExprNumberLiteral {
range: 97..98,
value: Int(
2,
),
},
),
},
DictItem {
key: Some(
NumberLiteral(
ExprNumberLiteral {
range: 100..101,
@ -55,17 +66,7 @@ Module(
},
),
),
],
values: [
NumberLiteral(
ExprNumberLiteral {
range: 97..98,
value: Int(
2,
),
},
),
NumberLiteral(
value: NumberLiteral(
ExprNumberLiteral {
range: 103..104,
value: Int(
@ -73,6 +74,7 @@ Module(
),
},
),
},
],
},
),
@ -84,8 +86,9 @@ Module(
value: Dict(
ExprDict {
range: 107..115,
keys: [
Some(
items: [
DictItem {
key: Some(
NumberLiteral(
ExprNumberLiteral {
range: 108..109,
@ -95,9 +98,7 @@ Module(
},
),
),
],
values: [
NumberLiteral(
value: NumberLiteral(
ExprNumberLiteral {
range: 111..112,
value: Int(
@ -105,6 +106,7 @@ Module(
),
},
),
},
],
},
),
@ -116,8 +118,9 @@ Module(
value: Dict(
ExprDict {
range: 133..144,
keys: [
Some(
items: [
DictItem {
key: Some(
NumberLiteral(
ExprNumberLiteral {
range: 134..135,
@ -127,7 +130,17 @@ Module(
},
),
),
Some(
value: NumberLiteral(
ExprNumberLiteral {
range: 137..138,
value: Int(
2,
),
},
),
},
DictItem {
key: Some(
NumberLiteral(
ExprNumberLiteral {
range: 139..140,
@ -137,17 +150,7 @@ Module(
},
),
),
],
values: [
NumberLiteral(
ExprNumberLiteral {
range: 137..138,
value: Int(
2,
),
},
),
NumberLiteral(
value: NumberLiteral(
ExprNumberLiteral {
range: 142..143,
value: Int(
@ -155,6 +158,7 @@ Module(
),
},
),
},
],
},
),
@ -166,8 +170,9 @@ Module(
value: Dict(
ExprDict {
range: 157..162,
keys: [
Some(
items: [
DictItem {
key: Some(
NumberLiteral(
ExprNumberLiteral {
range: 158..159,
@ -177,15 +182,14 @@ Module(
},
),
),
],
values: [
Name(
value: Name(
ExprName {
range: 160..160,
id: "",
ctx: Invalid,
},
),
},
],
},
),
@ -197,17 +201,17 @@ Module(
value: Dict(
ExprDict {
range: 201..205,
keys: [
None,
],
values: [
Name(
items: [
DictItem {
key: None,
value: Name(
ExprName {
range: 204..204,
id: "",
ctx: Invalid,
},
),
},
],
},
),
@ -219,8 +223,9 @@ Module(
value: Dict(
ExprDict {
range: 206..222,
keys: [
Some(
items: [
DictItem {
key: Some(
Name(
ExprName {
range: 207..208,
@ -229,8 +234,26 @@ Module(
},
),
),
None,
Some(
value: Name(
ExprName {
range: 210..211,
id: "y",
ctx: Load,
},
),
},
DictItem {
key: None,
value: Name(
ExprName {
range: 215..215,
id: "",
ctx: Invalid,
},
),
},
DictItem {
key: Some(
Name(
ExprName {
range: 217..218,
@ -239,29 +262,14 @@ Module(
},
),
),
],
values: [
Name(
ExprName {
range: 210..211,
id: "y",
ctx: Load,
},
),
Name(
ExprName {
range: 215..215,
id: "",
ctx: Invalid,
},
),
Name(
value: Name(
ExprName {
range: 220..221,
id: "b",
ctx: Load,
},
),
},
],
},
),
@ -273,8 +281,9 @@ Module(
value: Dict(
ExprDict {
range: 310..330,
keys: [
Some(
items: [
DictItem {
key: Some(
Starred(
ExprStarred {
range: 311..313,
@ -289,7 +298,16 @@ Module(
},
),
),
Some(
value: Name(
ExprName {
range: 315..316,
id: "y",
ctx: Load,
},
),
},
DictItem {
key: Some(
Name(
ExprName {
range: 318..319,
@ -298,7 +316,16 @@ Module(
},
),
),
Some(
value: Name(
ExprName {
range: 321..322,
id: "a",
ctx: Load,
},
),
},
DictItem {
key: Some(
Starred(
ExprStarred {
range: 324..326,
@ -313,29 +340,14 @@ Module(
},
),
),
],
values: [
Name(
ExprName {
range: 315..316,
id: "y",
ctx: Load,
},
),
Name(
ExprName {
range: 321..322,
id: "a",
ctx: Load,
},
),
Name(
value: Name(
ExprName {
range: 328..329,
id: "c",
ctx: Load,
},
),
},
],
},
),
@ -347,8 +359,9 @@ Module(
value: Dict(
ExprDict {
range: 331..345,
keys: [
Some(
items: [
DictItem {
key: Some(
Name(
ExprName {
range: 332..333,
@ -357,18 +370,7 @@ Module(
},
),
),
Some(
Name(
ExprName {
range: 339..340,
id: "z",
ctx: Load,
},
),
),
],
values: [
Starred(
value: Starred(
ExprStarred {
range: 335..337,
value: Name(
@ -381,7 +383,18 @@ Module(
ctx: Load,
},
),
Starred(
},
DictItem {
key: Some(
Name(
ExprName {
range: 339..340,
id: "z",
ctx: Load,
},
),
),
value: Starred(
ExprStarred {
range: 342..344,
value: Name(
@ -394,6 +407,7 @@ Module(
ctx: Load,
},
),
},
],
},
),

View file

@ -110,8 +110,9 @@ Module(
value: Dict(
ExprDict {
range: 271..277,
keys: [
Some(
items: [
DictItem {
key: Some(
NumberLiteral(
ExprNumberLiteral {
range: 272..273,
@ -121,9 +122,7 @@ Module(
},
),
),
],
values: [
NumberLiteral(
value: NumberLiteral(
ExprNumberLiteral {
range: 275..276,
value: Int(
@ -131,6 +130,7 @@ Module(
),
},
),
},
],
},
),

View file

@ -44,8 +44,9 @@ Module(
Dict(
ExprDict {
range: 14..22,
keys: [
Some(
items: [
DictItem {
key: Some(
StringLiteral(
ExprStringLiteral {
range: 15..18,
@ -65,9 +66,7 @@ Module(
},
),
),
],
values: [
NumberLiteral(
value: NumberLiteral(
ExprNumberLiteral {
range: 20..21,
value: Int(
@ -75,6 +74,7 @@ Module(
),
},
),
},
],
},
),

View file

@ -57,8 +57,9 @@ Module(
value: Dict(
ExprDict {
range: 20..36,
keys: [
Some(
items: [
DictItem {
key: Some(
StringLiteral(
ExprStringLiteral {
range: 21..24,
@ -78,7 +79,17 @@ Module(
},
),
),
Some(
value: NumberLiteral(
ExprNumberLiteral {
range: 26..27,
value: Int(
1,
),
},
),
},
DictItem {
key: Some(
StringLiteral(
ExprStringLiteral {
range: 29..32,
@ -98,17 +109,7 @@ Module(
},
),
),
],
values: [
NumberLiteral(
ExprNumberLiteral {
range: 26..27,
value: Int(
1,
),
},
),
NumberLiteral(
value: NumberLiteral(
ExprNumberLiteral {
range: 34..35,
value: Int(
@ -116,6 +117,7 @@ Module(
),
},
),
},
],
},
),

View file

@ -319,8 +319,9 @@ Module(
Dict(
ExprDict {
range: 386..394,
keys: [
Some(
items: [
DictItem {
key: Some(
StringLiteral(
ExprStringLiteral {
range: 387..390,
@ -340,9 +341,7 @@ Module(
},
),
),
],
values: [
NumberLiteral(
value: NumberLiteral(
ExprNumberLiteral {
range: 392..393,
value: Int(
@ -350,6 +349,7 @@ Module(
),
},
),
},
],
},
),

View file

@ -236,8 +236,9 @@ Module(
target: Dict(
ExprDict {
range: 186..194,
keys: [
Some(
items: [
DictItem {
key: Some(
StringLiteral(
ExprStringLiteral {
range: 187..190,
@ -257,9 +258,7 @@ Module(
},
),
),
],
values: [
NumberLiteral(
value: NumberLiteral(
ExprNumberLiteral {
range: 192..193,
value: Int(
@ -267,6 +266,7 @@ Module(
),
},
),
},
],
},
),

View file

@ -28,8 +28,7 @@ Module(
cls: Dict(
ExprDict {
range: 108..109,
keys: [],
values: [],
items: [],
},
),
arguments: PatternArguments {

View file

@ -263,8 +263,9 @@ Module(
left: Dict(
ExprDict {
range: 201..210,
keys: [
Some(
items: [
DictItem {
key: Some(
BooleanLiteral(
ExprBooleanLiteral {
range: 202..206,
@ -272,9 +273,7 @@ Module(
},
),
),
],
values: [
NumberLiteral(
value: NumberLiteral(
ExprNumberLiteral {
range: 208..209,
value: Int(
@ -282,6 +281,7 @@ Module(
),
},
),
},
],
},
),
@ -711,8 +711,9 @@ Module(
right: Dict(
ExprDict {
range: 534..543,
keys: [
Some(
items: [
DictItem {
key: Some(
BooleanLiteral(
ExprBooleanLiteral {
range: 535..539,
@ -720,9 +721,7 @@ Module(
},
),
),
],
values: [
NumberLiteral(
value: NumberLiteral(
ExprNumberLiteral {
range: 541..542,
value: Int(
@ -730,6 +729,7 @@ Module(
),
},
),
},
],
},
),

View file

@ -192,8 +192,9 @@ Module(
value: Dict(
ExprDict {
range: 76..82,
keys: [
Some(
items: [
DictItem {
key: Some(
Name(
ExprName {
range: 77..78,
@ -202,9 +203,7 @@ Module(
},
),
),
],
values: [
NumberLiteral(
value: NumberLiteral(
ExprNumberLiteral {
range: 80..81,
value: Int(
@ -212,6 +211,7 @@ Module(
),
},
),
},
],
},
),

View file

@ -360,8 +360,9 @@ Module(
func: Dict(
ExprDict {
range: 219..231,
keys: [
Some(
items: [
DictItem {
key: Some(
NumberLiteral(
ExprNumberLiteral {
range: 220..221,
@ -371,7 +372,17 @@ Module(
},
),
),
Some(
value: NumberLiteral(
ExprNumberLiteral {
range: 223..224,
value: Int(
2,
),
},
),
},
DictItem {
key: Some(
NumberLiteral(
ExprNumberLiteral {
range: 226..227,
@ -381,17 +392,7 @@ Module(
},
),
),
],
values: [
NumberLiteral(
ExprNumberLiteral {
range: 223..224,
value: Int(
2,
),
},
),
NumberLiteral(
value: NumberLiteral(
ExprNumberLiteral {
range: 229..230,
value: Int(
@ -399,6 +400,7 @@ Module(
),
},
),
},
],
},
),

View file

@ -15,8 +15,7 @@ Module(
value: Dict(
ExprDict {
range: 9..11,
keys: [],
values: [],
items: [],
},
),
},
@ -27,8 +26,9 @@ Module(
value: Dict(
ExprDict {
range: 12..18,
keys: [
Some(
items: [
DictItem {
key: Some(
NumberLiteral(
ExprNumberLiteral {
range: 13..14,
@ -38,9 +38,7 @@ Module(
},
),
),
],
values: [
NumberLiteral(
value: NumberLiteral(
ExprNumberLiteral {
range: 16..17,
value: Int(
@ -48,6 +46,7 @@ Module(
),
},
),
},
],
},
),
@ -59,8 +58,9 @@ Module(
value: Dict(
ExprDict {
range: 19..43,
keys: [
Some(
items: [
DictItem {
key: Some(
NumberLiteral(
ExprNumberLiteral {
range: 20..21,
@ -70,7 +70,17 @@ Module(
},
),
),
Some(
value: NumberLiteral(
ExprNumberLiteral {
range: 23..24,
value: Int(
2,
),
},
),
},
DictItem {
key: Some(
Name(
ExprName {
range: 26..27,
@ -79,7 +89,17 @@ Module(
},
),
),
Some(
value: NumberLiteral(
ExprNumberLiteral {
range: 29..30,
value: Int(
1,
),
},
),
},
DictItem {
key: Some(
Name(
ExprName {
range: 32..33,
@ -88,25 +108,7 @@ Module(
},
),
),
],
values: [
NumberLiteral(
ExprNumberLiteral {
range: 23..24,
value: Int(
2,
),
},
),
NumberLiteral(
ExprNumberLiteral {
range: 29..30,
value: Int(
1,
),
},
),
StringLiteral(
value: StringLiteral(
ExprStringLiteral {
range: 35..42,
value: StringLiteralValue {
@ -124,6 +126,7 @@ Module(
},
},
),
},
],
},
),
@ -135,8 +138,7 @@ Module(
value: Dict(
ExprDict {
range: 66..69,
keys: [],
values: [],
items: [],
},
),
},
@ -147,8 +149,9 @@ Module(
value: Dict(
ExprDict {
range: 70..100,
keys: [
Some(
items: [
DictItem {
key: Some(
NumberLiteral(
ExprNumberLiteral {
range: 76..77,
@ -158,7 +161,17 @@ Module(
},
),
),
Some(
value: NumberLiteral(
ExprNumberLiteral {
range: 83..84,
value: Int(
2,
),
},
),
},
DictItem {
key: Some(
NumberLiteral(
ExprNumberLiteral {
range: 90..91,
@ -168,17 +181,7 @@ Module(
},
),
),
],
values: [
NumberLiteral(
ExprNumberLiteral {
range: 83..84,
value: Int(
2,
),
},
),
NumberLiteral(
value: NumberLiteral(
ExprNumberLiteral {
range: 97..98,
value: Int(
@ -186,6 +189,7 @@ Module(
),
},
),
},
],
},
),
@ -197,13 +201,15 @@ Module(
value: Dict(
ExprDict {
range: 111..132,
keys: [
Some(
items: [
DictItem {
key: Some(
Dict(
ExprDict {
range: 112..118,
keys: [
Some(
items: [
DictItem {
key: Some(
NumberLiteral(
ExprNumberLiteral {
range: 113..114,
@ -213,9 +219,7 @@ Module(
},
),
),
],
values: [
NumberLiteral(
value: NumberLiteral(
ExprNumberLiteral {
range: 116..117,
value: Int(
@ -223,17 +227,17 @@ Module(
),
},
),
},
],
},
),
),
],
values: [
Dict(
value: Dict(
ExprDict {
range: 120..131,
keys: [
Some(
items: [
DictItem {
key: Some(
NumberLiteral(
ExprNumberLiteral {
range: 121..122,
@ -243,13 +247,12 @@ Module(
},
),
),
],
values: [
Dict(
value: Dict(
ExprDict {
range: 124..130,
keys: [
Some(
items: [
DictItem {
key: Some(
NumberLiteral(
ExprNumberLiteral {
range: 125..126,
@ -259,9 +262,7 @@ Module(
},
),
),
],
values: [
NumberLiteral(
value: NumberLiteral(
ExprNumberLiteral {
range: 128..129,
value: Int(
@ -269,12 +270,15 @@ Module(
),
},
),
},
],
},
),
},
],
},
),
},
],
},
),
@ -286,8 +290,9 @@ Module(
value: Dict(
ExprDict {
range: 155..171,
keys: [
Some(
items: [
DictItem {
key: Some(
Lambda(
ExprLambda {
range: 156..167,
@ -324,9 +329,7 @@ Module(
},
),
),
],
values: [
NumberLiteral(
value: NumberLiteral(
ExprNumberLiteral {
range: 169..170,
value: Int(
@ -334,6 +337,7 @@ Module(
),
},
),
},
],
},
),
@ -345,8 +349,9 @@ Module(
value: Dict(
ExprDict {
range: 172..202,
keys: [
Some(
items: [
DictItem {
key: Some(
StringLiteral(
ExprStringLiteral {
range: 173..176,
@ -366,29 +371,7 @@ Module(
},
),
),
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(
value: Lambda(
ExprLambda {
range: 178..192,
parameters: Some(
@ -421,13 +404,36 @@ Module(
),
},
),
Name(
},
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,
},
},
),
},
},
),
),
value: Name(
ExprName {
range: 199..200,
id: "C",
ctx: Load,
},
),
},
],
},
),
@ -439,8 +445,9 @@ Module(
value: Dict(
ExprDict {
range: 224..237,
keys: [
Some(
items: [
DictItem {
key: Some(
Named(
ExprNamed {
range: 226..232,
@ -462,15 +469,14 @@ Module(
},
),
),
],
values: [
Name(
value: Name(
ExprName {
range: 235..236,
id: "y",
ctx: Load,
},
),
},
],
},
),
@ -482,8 +488,9 @@ Module(
value: Dict(
ExprDict {
range: 238..258,
keys: [
Some(
items: [
DictItem {
key: Some(
Named(
ExprNamed {
range: 240..246,
@ -505,9 +512,7 @@ Module(
},
),
),
],
values: [
Named(
value: Named(
ExprNamed {
range: 250..256,
target: Name(
@ -527,6 +532,7 @@ Module(
),
},
),
},
],
},
),
@ -538,17 +544,17 @@ Module(
value: Dict(
ExprDict {
range: 284..289,
keys: [
None,
],
values: [
Name(
items: [
DictItem {
key: None,
value: Name(
ExprName {
range: 287..288,
id: "d",
ctx: Load,
},
),
},
],
},
),
@ -560,8 +566,9 @@ Module(
value: Dict(
ExprDict {
range: 290..301,
keys: [
Some(
items: [
DictItem {
key: Some(
Name(
ExprName {
range: 291..292,
@ -570,23 +577,24 @@ Module(
},
),
),
None,
],
values: [
Name(
value: Name(
ExprName {
range: 294..295,
id: "b",
ctx: Load,
},
),
Name(
},
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(
items: [
DictItem {
key: None,
value: Name(
ExprName {
range: 305..306,
id: "a",
ctx: Load,
},
),
Name(
},
DictItem {
key: None,
value: Name(
ExprName {
range: 310..311,
id: "b",
ctx: Load,
},
),
},
],
},
),
@ -628,8 +638,9 @@ Module(
value: Dict(
ExprDict {
range: 313..338,
keys: [
Some(
items: [
DictItem {
key: Some(
StringLiteral(
ExprStringLiteral {
range: 314..317,
@ -649,8 +660,37 @@ Module(
},
),
),
None,
Some(
value: 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,
},
},
),
},
},
),
},
DictItem {
key: None,
value: Name(
ExprName {
range: 326..327,
id: "c",
ctx: Load,
},
),
},
DictItem {
key: Some(
StringLiteral(
ExprStringLiteral {
range: 329..332,
@ -670,34 +710,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(
value: StringLiteral(
ExprStringLiteral {
range: 334..337,
value: StringLiteralValue {
@ -715,6 +728,7 @@ Module(
},
},
),
},
],
},
),
@ -726,8 +740,9 @@ Module(
value: Dict(
ExprDict {
range: 339..367,
keys: [
Some(
items: [
DictItem {
key: Some(
NumberLiteral(
ExprNumberLiteral {
range: 340..341,
@ -737,10 +752,7 @@ Module(
},
),
),
None,
],
values: [
NumberLiteral(
value: NumberLiteral(
ExprNumberLiteral {
range: 343..344,
value: Int(
@ -748,11 +760,15 @@ Module(
),
},
),
Dict(
},
DictItem {
key: None,
value: Dict(
ExprDict {
range: 348..366,
keys: [
Some(
items: [
DictItem {
key: Some(
StringLiteral(
ExprStringLiteral {
range: 349..357,
@ -772,9 +788,7 @@ Module(
},
),
),
],
values: [
StringLiteral(
value: StringLiteral(
ExprStringLiteral {
range: 359..365,
value: StringLiteralValue {
@ -792,9 +806,11 @@ Module(
},
},
),
},
],
},
),
},
],
},
),
@ -806,8 +822,9 @@ Module(
value: Dict(
ExprDict {
range: 368..393,
keys: [
Some(
items: [
DictItem {
key: Some(
BinOp(
ExprBinOp {
range: 369..374,
@ -830,10 +847,7 @@ Module(
},
),
),
None,
],
values: [
BinOp(
value: BinOp(
ExprBinOp {
range: 376..382,
left: Name(
@ -854,7 +868,10 @@ Module(
),
},
),
Call(
},
DictItem {
key: None,
value: Call(
ExprCall {
range: 386..392,
func: Name(
@ -871,6 +888,7 @@ Module(
},
},
),
},
],
},
),
@ -882,11 +900,10 @@ Module(
value: Dict(
ExprDict {
range: 460..471,
keys: [
None,
],
values: [
UnaryOp(
items: [
DictItem {
key: None,
value: UnaryOp(
ExprUnaryOp {
range: 464..469,
op: Not,
@ -899,6 +916,7 @@ Module(
),
},
),
},
],
},
),
@ -910,8 +928,9 @@ Module(
value: Dict(
ExprDict {
range: 494..515,
keys: [
Some(
items: [
DictItem {
key: Some(
NumberLiteral(
ExprNumberLiteral {
range: 495..496,
@ -921,9 +940,7 @@ Module(
},
),
),
],
values: [
If(
value: If(
ExprIf {
range: 498..514,
test: BooleanLiteral(
@ -948,6 +965,7 @@ Module(
),
},
),
},
],
},
),
@ -1079,8 +1097,9 @@ Module(
value: Dict(
ExprDict {
range: 576..600,
keys: [
Some(
items: [
DictItem {
key: Some(
Set(
ExprSet {
range: 577..583,
@ -1105,7 +1124,17 @@ Module(
},
),
),
Some(
value: NumberLiteral(
ExprNumberLiteral {
range: 585..586,
value: Int(
3,
),
},
),
},
DictItem {
key: Some(
Name(
ExprName {
range: 588..589,
@ -1114,21 +1143,12 @@ Module(
},
),
),
],
values: [
NumberLiteral(
ExprNumberLiteral {
range: 585..586,
value: Int(
3,
),
},
),
Dict(
value: Dict(
ExprDict {
range: 591..598,
keys: [
Some(
items: [
DictItem {
key: Some(
NumberLiteral(
ExprNumberLiteral {
range: 592..593,
@ -1138,9 +1158,7 @@ Module(
},
),
),
],
values: [
NumberLiteral(
value: NumberLiteral(
ExprNumberLiteral {
range: 595..596,
value: Int(
@ -1148,9 +1166,11 @@ Module(
),
},
),
},
],
},
),
},
],
},
),
@ -1162,8 +1182,9 @@ Module(
value: Dict(
ExprDict {
range: 601..621,
keys: [
Some(
items: [
DictItem {
key: Some(
Name(
ExprName {
range: 603..604,
@ -1172,7 +1193,16 @@ Module(
},
),
),
Some(
value: Name(
ExprName {
range: 608..609,
id: "y",
ctx: Load,
},
),
},
DictItem {
key: Some(
Name(
ExprName {
range: 613..614,
@ -1181,22 +1211,14 @@ Module(
},
),
),
],
values: [
Name(
ExprName {
range: 608..609,
id: "y",
ctx: Load,
},
),
Name(
value: Name(
ExprName {
range: 618..619,
id: "a",
ctx: Load,
},
),
},
],
},
),

View file

@ -823,8 +823,9 @@ Module(
value: Dict(
ExprDict {
range: 219..253,
keys: [
Some(
items: [
DictItem {
key: Some(
FString(
ExprFString {
range: 220..248,
@ -911,9 +912,7 @@ Module(
},
),
),
],
values: [
NumberLiteral(
value: NumberLiteral(
ExprNumberLiteral {
range: 250..252,
value: Int(
@ -921,6 +920,7 @@ Module(
),
},
),
},
],
},
),

View file

@ -652,8 +652,9 @@ Module(
Dict(
ExprDict {
range: 319..325,
keys: [
Some(
items: [
DictItem {
key: Some(
Name(
ExprName {
range: 320..321,
@ -662,9 +663,7 @@ Module(
},
),
),
],
values: [
NumberLiteral(
value: NumberLiteral(
ExprNumberLiteral {
range: 323..324,
value: Int(
@ -672,6 +671,7 @@ Module(
),
},
),
},
],
},
),

View file

@ -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,8 +577,9 @@ Module(
Dict(
ExprDict {
range: 300..311,
keys: [
Some(
items: [
DictItem {
key: Some(
Name(
ExprName {
range: 301..302,
@ -589,23 +588,24 @@ Module(
},
),
),
None,
],
values: [
Name(
value: Name(
ExprName {
range: 304..305,
id: "b",
ctx: Load,
},
),
Name(
},
DictItem {
key: None,
value: Name(
ExprName {
range: 309..310,
id: "d",
ctx: Load,
},
),
},
],
},
),

View file

@ -216,8 +216,9 @@ Module(
Dict(
ExprDict {
range: 85..91,
keys: [
Some(
items: [
DictItem {
key: Some(
Name(
ExprName {
range: 86..87,
@ -226,9 +227,7 @@ Module(
},
),
),
],
values: [
NumberLiteral(
value: NumberLiteral(
ExprNumberLiteral {
range: 89..90,
value: Int(
@ -236,6 +235,7 @@ Module(
),
},
),
},
],
},
),

View file

@ -192,8 +192,9 @@ Module(
value: Dict(
ExprDict {
range: 114..120,
keys: [
Some(
items: [
DictItem {
key: Some(
Name(
ExprName {
range: 115..116,
@ -202,9 +203,7 @@ Module(
},
),
),
],
values: [
NumberLiteral(
value: NumberLiteral(
ExprNumberLiteral {
range: 118..119,
value: Int(
@ -212,6 +211,7 @@ Module(
),
},
),
},
],
},
),

View file

@ -3814,8 +3814,9 @@ Module(
subject: Dict(
ExprDict {
range: 2959..2970,
keys: [
Some(
items: [
DictItem {
key: Some(
StringLiteral(
ExprStringLiteral {
range: 2960..2966,
@ -3835,9 +3836,7 @@ Module(
},
),
),
],
values: [
NumberLiteral(
value: NumberLiteral(
ExprNumberLiteral {
range: 2968..2969,
value: Int(
@ -3845,6 +3844,7 @@ Module(
),
},
),
},
],
},
),
@ -3907,8 +3907,9 @@ Module(
subject: Dict(
ExprDict {
range: 3032..3049,
keys: [
Some(
items: [
DictItem {
key: Some(
StringLiteral(
ExprStringLiteral {
range: 3033..3040,
@ -3928,9 +3929,7 @@ Module(
},
),
),
],
values: [
StringLiteral(
value: StringLiteral(
ExprStringLiteral {
range: 3042..3048,
value: StringLiteralValue {
@ -3948,6 +3947,7 @@ Module(
},
},
),
},
],
},
),