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

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

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);
}
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: _ }) => {

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);
}
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: _ }) => {

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,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,
},
),
],
},
),
},
],
},
),

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

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,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,
},
),
},
],
},
),

View file

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

View file

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

View file

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