From 177cfed5b5e0ea6a1a66d2545a1424e2c57040f2 Mon Sep 17 00:00:00 2001 From: Glyphack Date: Tue, 25 Feb 2025 20:19:56 +0100 Subject: [PATCH] Apply review suggestions --- crates/ruff_python_ast/ast.toml | 432 +++++++++++++++++------- crates/ruff_python_ast/generate.py | 27 +- crates/ruff_python_ast/src/generated.rs | 4 +- crates/ruff_python_ast/src/nodes.rs | 268 --------------- 4 files changed, 332 insertions(+), 399 deletions(-) diff --git a/crates/ruff_python_ast/ast.toml b/crates/ruff_python_ast/ast.toml index 7fe48f5fae9398..1b449d700ed581 100644 --- a/crates/ruff_python_ast/ast.toml +++ b/crates/ruff_python_ast/ast.toml @@ -80,130 +80,314 @@ add_suffix_to_is_methods = true anynode_is_label = "expression" rustdoc = "/// See also [expr](https://docs.python.org/3/library/ast.html#ast.expr)" -[Expr.nodes] -ExprBoolOp = { fields = [ - { name = "op", type = "BoolOp" }, - { name = "values", type = "Expr", seq = true } -]} -ExprNamed = { fields = [ - { name = "target", type = "Expr" }, - { name = "value", type = "Expr" } -]} -ExprBinOp = { fields = [ - { name = "left", type = "Expr" }, - { name = "op", type = "Operator" }, - { name = "right", type = "Expr" } -]} -ExprUnaryOp = { fields = [ - { name = "op", type = "UnaryOp" }, - { name = "operand", type = "Expr" } -]} -ExprLambda = { fields = [ - { name = "parameters", type = "Box", optional = true }, - { name = "body", type = "Expr" } -]} -ExprIf = { fields = [ - { name = "test", type = "Expr" }, - { name = "body", type = "Expr" }, - { name = "orelse", type = "Expr" } -]} -ExprDict = { fields = [ - { name = "items", type = "DictItem", seq = true }, -]} -ExprSet = { fields = [ - { name = "elts", type = "Expr", seq = true } -]} -ExprListComp = { fields = [ - { name = "elt", type = "Expr" }, - { name = "generators", type = "Comprehension", seq = true } -]} -ExprSetComp = { fields = [ - { name = "elt", type = "Expr" }, - { name = "generators", type = "Comprehension", seq = true } -]} -ExprDictComp = { fields = [ - { name = "key", type = "Expr" }, - { name = "value", type = "Expr" }, - { name = "generators", type = "Comprehension", seq = true } -]} -ExprGenerator = { fields = [ - { name = "elt", type = "Expr" }, - { name = "generators", type = "Comprehension", seq = true }, - { name = "parenthesized", type = "bool" } -]} -ExprAwait = { fields = [ - { name = "value", type = "Expr" } -]} -ExprYield = { fields = [ - { name = "value", type = "Expr", optional = true } -]} -ExprYieldFrom = { fields = [ - { name = "value", type = "Expr" } -]} -ExprCompare = { fields = [ - { name = "left", type = "Expr" }, - # TODO: We don't want this field to be a vec hence the seq is not enabled. - { name = "ops", type = "Box<[crate::CmpOp]>"}, - { name = "comparators", type = "Box<[Expr]>"} -]} -ExprCall = { fields = [ - { name = "func", type = "Expr" }, - { name = "arguments", type = "Arguments"} -]} -ExprFString = { fields = [ - { name = "value", type = "FStringValue" } -]} -ExprStringLiteral = { fields = [ - { name = "value", type = "StringLiteralValue" } -]} -ExprBytesLiteral = { fields = [ - { name = "value", type = "BytesLiteralValue" } -]} -ExprNumberLiteral = { fields = [ - { name = "value", type = "Number" } -]} -ExprBooleanLiteral = { fields = [ - { name = "value", type = "bool" } -], derives = ["Default"]} -ExprNoneLiteral = { fields = [], derives = ["Default"]} -ExprEllipsisLiteral = { fields = [], derives = ["Default"]} -ExprAttribute = { fields = [ - { name = "value", type = "Expr" }, - { name = "attr", type = "Identifier" }, - { name = "ctx", type = "ExprContext" } -]} -ExprSubscript = { fields = [ - { name = "value", type = "Expr" }, - { name = "slice", type = "Expr" }, - { name = "ctx", type = "ExprContext" } -]} -ExprStarred = { fields = [ - { name = "value", type = "Expr" }, - { name = "ctx", type = "ExprContext" } -]} -ExprName = { fields = [ - { name = "id", type = "name::Name" }, - { name = "ctx", type = "ExprContext" } -]} -ExprList = { fields = [ - { name = "elts", type = "Expr", seq = true }, - { name = "ctx", type = "ExprContext" } -]} -ExprTuple = { fields = [ - { name = "elts", type = "Expr", seq = true }, - { name = "ctx", type = "ExprContext" }, - { name = "parenthesized", type = "bool" } -]} -ExprSlice = { fields = [ - { name = "lower", type = "Expr", optional = true }, - { name = "upper", type = "Expr", optional = true }, - { name = "step", type = "Expr", optional = true } -]} -ExprIpyEscapeCommand = { fields = [ - { name = "kind", type = "IpyEscapeKind" }, - { name = "value", type = "Box" } - -]} +# See also [BoolOp](https://docs.python.org/3/library/ast.html#ast.BoolOp) +[[Expr.nodes.ExprBoolOp.fields]] +name = "op" +type = "BoolOp" + +[[Expr.nodes.ExprBoolOp.fields]] +name = "values" +type = "Expr" +seq = true + +# See also [NamedExpr](https://docs.python.org/3/library/ast.html#ast.NamedExpr) +[[Expr.nodes.ExprNamed.fields]] +name = "target" +type = "Expr" + +[[Expr.nodes.ExprNamed.fields]] +name = "value" +type = "Expr" + +# See also [BinOp](https://docs.python.org/3/library/ast.html#ast.BinOp) +[[Expr.nodes.ExprBinOp.fields]] +name = "left" +type = "Expr" + +[[Expr.nodes.ExprBinOp.fields]] +name = "op" +type = "Operator" + +[[Expr.nodes.ExprBinOp.fields]] +name = "right" +type = "Expr" + +# See also [UnaryOp](https://docs.python.org/3/library/ast.html#ast.UnaryOp) +[[Expr.nodes.ExprUnaryOp.fields]] +name = "op" +type = "UnaryOp" + +[[Expr.nodes.ExprUnaryOp.fields]] +name = "operand" +type = "Expr" + +# See also [Lambda](https://docs.python.org/3/library/ast.html#ast.Lambda) +[[Expr.nodes.ExprLambda.fields]] +name = "parameters" +type = "Box" +optional = true + +[[Expr.nodes.ExprLambda.fields]] +name = "body" +type = "Expr" + +# See also [IfExp](https://docs.python.org/3/library/ast.html#ast.IfExp) +[[Expr.nodes.ExprIf.fields]] +name = "test" +type = "Expr" + +[[Expr.nodes.ExprIf.fields]] +name = "body" +type = "Expr" + +[[Expr.nodes.ExprIf.fields]] +name = "orelse" +type = "Expr" + +# See also [Dict](https://docs.python.org/3/library/ast.html#ast.Dict) +[[Expr.nodes.ExprDict.fields]] +name = "items" +type = "DictItem" +seq = true + +# See also [Set](https://docs.python.org/3/library/ast.html#ast.Set) +[[Expr.nodes.ExprSet.fields]] +name = "elts" +type = "Expr" +seq = true + +# See also [ListComp](https://docs.python.org/3/library/ast.html#ast.ListComp) +[[Expr.nodes.ExprListComp.fields]] +name = "elt" +type = "Expr" + +[[Expr.nodes.ExprListComp.fields]] +name = "generators" +type = "Comprehension" +seq = true + +# See also [SetComp](https://docs.python.org/3/library/ast.html#ast.SetComp) +[[Expr.nodes.ExprSetComp.fields]] +name = "elt" +type = "Expr" + +[[Expr.nodes.ExprSetComp.fields]] +name = "generators" +type = "Comprehension" +seq = true + +# See also [DictComp](https://docs.python.org/3/library/ast.html#ast.DictComp) +[[Expr.nodes.ExprDictComp.fields]] +name = "key" +type = "Expr" + +[[Expr.nodes.ExprDictComp.fields]] +name = "value" +type = "Expr" + +[[Expr.nodes.ExprDictComp.fields]] +name = "generators" +type = "Comprehension" +seq = true + +# See also [GeneratorExp](https://docs.python.org/3/library/ast.html#ast.GeneratorExp) +[[Expr.nodes.ExprGenerator.fields]] +name = "elt" +type = "Expr" + +[[Expr.nodes.ExprGenerator.fields]] +name = "generators" +type = "Comprehension" +seq = true + +[[Expr.nodes.ExprGenerator.fields]] +name = "parenthesized" +type = "bool" + +# See also [Await](https://docs.python.org/3/library/ast.html#ast.Await) +[[Expr.nodes.ExprAwait.fields]] +name = "value" +type = "Expr" + +# See also [Yield](https://docs.python.org/3/library/ast.html#ast.Yield) +[[Expr.nodes.ExprYield.fields]] +name = "value" +type = "Expr" +optional = true + +# See also [YieldFrom](https://docs.python.org/3/library/ast.html#ast.YieldFrom) +[[Expr.nodes.ExprYieldFrom.fields]] +name = "value" +type = "Expr" + +# See also [Compare](https://docs.python.org/3/library/ast.html#ast.Compare) +[[Expr.nodes.ExprCompare.fields]] +name = "left" +type = "Expr" + +[[Expr.nodes.ExprCompare.fields]] +name = "ops" +type = "Box<[crate::CmpOp]>" + +[[Expr.nodes.ExprCompare.fields]] +name = "comparators" +type = "Box<[Expr]>" + +# See also [Call](https://docs.python.org/3/library/ast.html#ast.Call) +[[Expr.nodes.ExprCall.fields]] +name = "func" +type = "Expr" + +[[Expr.nodes.ExprCall.fields]] +name = "arguments" +type = "Arguments" + +# An AST node that represents either a single-part f-string literal +# or an implicitly concatenated f-string literal. +# +# This type differs from the original Python AST ([JoinedStr]) in that it +# doesn't join the implicitly concatenated parts into a single string. Instead, +# it keeps them separate and provide various methods to access the parts. +# +# [JoinedStr]: https://docs.python.org/3/library/ast.html#ast.JoinedStr +[[Expr.nodes.ExprFString.fields]] +name = "value" +type = "FStringValue" + +# An AST node that represents either a single-part string literal +# or an implicitly concatenated string literal. +[[Expr.nodes.ExprStringLiteral.fields]] +name = "value" +type = "StringLiteralValue" + +# An AST node that represents either a single-part bytestring literal +# or an implicitly concatenated bytestring literal. +[[Expr.nodes.ExprBytesLiteral.fields]] +name = "value" +type = "BytesLiteralValue" + +[[Expr.nodes.ExprNumberLiteral.fields]] +name = "value" +type = "Number" + +[[Expr.nodes.ExprBooleanLiteral.fields]] +name = "value" +type = "bool" + +[Expr.nodes.ExprBooleanLiteral] +derives = ["Default"] + +[Expr.nodes.ExprNoneLiteral] +fields = [] +derives = ["Default"] + +[Expr.nodes.ExprEllipsisLiteral] +fields = [] +derives = ["Default"] + +# See also [Attribute](https://docs.python.org/3/library/ast.html#ast.Attribute) +[[Expr.nodes.ExprAttribute.fields]] +name = "value" +type = "Expr" + +[[Expr.nodes.ExprAttribute.fields]] +name = "attr" +type = "Identifier" + +[[Expr.nodes.ExprAttribute.fields]] +name = "ctx" +type = "ExprContext" + +# See also [Subscript](https://docs.python.org/3/library/ast.html#ast.Subscript) +[[Expr.nodes.ExprSubscript.fields]] +name = "value" +type = "Expr" + +[[Expr.nodes.ExprSubscript.fields]] +name = "slice" +type = "Expr" + +[[Expr.nodes.ExprSubscript.fields]] +name = "ctx" +type = "ExprContext" + +# See also [Starred](https://docs.python.org/3/library/ast.html#ast.Starred) +[[Expr.nodes.ExprStarred.fields]] +name = "value" +type = "Expr" + +[[Expr.nodes.ExprStarred.fields]] +name = "ctx" +type = "ExprContext" + +# See also [Name](https://docs.python.org/3/library/ast.html#ast.Name) +[[Expr.nodes.ExprName.fields]] +name = "id" +type = "Name" + +[[Expr.nodes.ExprName.fields]] +name = "ctx" +type = "ExprContext" + +# See also [List](https://docs.python.org/3/library/ast.html#ast.List) +[[Expr.nodes.ExprList.fields]] +name = "elts" +type = "Expr" +seq = true + +[[Expr.nodes.ExprList.fields]] +name = "ctx" +type = "ExprContext" + +# See also [Tuple](https://docs.python.org/3/library/ast.html#ast.Tuple) +[[Expr.nodes.ExprTuple.fields]] +name = "elts" +type = "Expr" +seq = true + +[[Expr.nodes.ExprTuple.fields]] +name = "ctx" +type = "ExprContext" + +[[Expr.nodes.ExprTuple.fields]] +name = "parenthesized" +type = "bool" + +# See also [Slice](https://docs.python.org/3/library/ast.html#ast.Slice) +[[Expr.nodes.ExprSlice.fields]] +name = "lower" +type = "Expr" +optional = true + +[[Expr.nodes.ExprSlice.fields]] +name = "upper" +type = "Expr" +optional = true + +[[Expr.nodes.ExprSlice.fields]] +name = "step" +type = "Expr" +optional = true + +# An AST node used to represent a IPython escape command at the expression level. +# +# For example, +# ```python +# dir = !pwd +# ``` +# +# Here, the escape kind can only be `!` or `%` otherwise it is a syntax error. +# +# For more information related to terminology and syntax of escape commands, +# see [`StmtIpyEscapeCommand`]. +[[Expr.nodes.ExprIpyEscapeCommand.fields]] +name = "kind" +type = "IpyEscapeKind" + +[[Expr.nodes.ExprIpyEscapeCommand.fields]] +name = "value" +type = "Box" + [ExceptHandler] rustdoc = "/// See also [excepthandler](https://docs.python.org/3/library/ast.html#ast.excepthandler)" diff --git a/crates/ruff_python_ast/generate.py b/crates/ruff_python_ast/generate.py index da86ce2c1567bf..006a0f56763862 100644 --- a/crates/ruff_python_ast/generate.py +++ b/crates/ruff_python_ast/generate.py @@ -14,6 +14,16 @@ import tomllib +imports = ["crate::name::Name"] + + +def require_crate_prefix(ty: str) -> bool: + no_crate_prefix_types = [ + "Name", # Imported at the top + "bool", + ] + return not (ty in no_crate_prefix_types or ty.startswith("Box")) + def rustfmt(code: str) -> str: return check_output(["rustfmt", "--emit=stdout"], input=code, text=True) @@ -91,7 +101,7 @@ class Node: variant: str ty: str fields: list[Field] | None - derives: list[str] | None + derives: list[str] def __init__(self, group: Group, node_name: str, node: dict[str, Any]) -> None: self.name = node_name @@ -123,9 +133,12 @@ def __init__(self, field: dict[str, Any]) -> None: def write_preamble(out: list[str]) -> None: - out.append(""" + import_section = "\n".join(f"use {im};" for im in imports) + out.append(f""" // This is a generated file. Don't modify it by hand! // Run `crates/ruff_python_ast/generate.py` to re-generate the file. + + { import_section } """) @@ -572,6 +585,7 @@ def write_nodekind(out: list[str], ast: Ast) -> None: def write_node(out: list[str], ast: Ast) -> None: + group_names = [group.name for group in ast.groups] for group in ast.groups: for node in group.nodes: if node.fields is None: @@ -586,10 +600,11 @@ def write_node(out: list[str], ast: Ast) -> None: out.append("pub range: ruff_text_size::TextRange,") for field in node.fields: field_str = f"pub {field.name}: " - inner = f"crate::{field.ty}" - if field.ty == "bool" or field.ty.startswith("Box"): - inner = field.ty - if field.ty == group.name and field.seq is False: + + inner = f"{field.ty}" + if require_crate_prefix(field.ty): + inner = f"crate::{inner}" + if field.ty in group_names and field.seq is False: inner = f"Box<{inner}>" if field.seq: diff --git a/crates/ruff_python_ast/src/generated.rs b/crates/ruff_python_ast/src/generated.rs index a4f5ba4ef1c205..0017f7d0c2359e 100644 --- a/crates/ruff_python_ast/src/generated.rs +++ b/crates/ruff_python_ast/src/generated.rs @@ -1,6 +1,8 @@ // This is a generated file. Don't modify it by hand! // Run `crates/ruff_python_ast/generate.py` to re-generate the file. +use crate::name::Name; + /// See also [mod](https://docs.python.org/3/library/ast.html#ast.mod) #[derive(Clone, Debug, PartialEq)] pub enum Mod { @@ -6631,7 +6633,7 @@ pub struct ExprStarred { #[derive(Clone, Debug, PartialEq)] pub struct ExprName { pub range: ruff_text_size::TextRange, - pub id: crate::name::Name, + pub id: Name, pub ctx: crate::ExprContext, } diff --git a/crates/ruff_python_ast/src/nodes.rs b/crates/ruff_python_ast/src/nodes.rs index 055ffe59835a79..da38b42c5a8670 100644 --- a/crates/ruff_python_ast/src/nodes.rs +++ b/crates/ruff_python_ast/src/nodes.rs @@ -384,74 +384,6 @@ impl ExprRef<'_> { } } -// /// An AST node used to represent a IPython escape command at the expression level. -// /// -// /// For example, -// /// ```python -// /// dir = !pwd -// /// ``` -// /// -// /// Here, the escape kind can only be `!` or `%` otherwise it is a syntax error. -// /// -// /// For more information related to terminology and syntax of escape commands, -// /// see [`StmtIpyEscapeCommand`]. -// #[derive(Clone, Debug, PartialEq)] -// pub struct ExprIpyEscapeCommand { -// pub range: TextRange, -// pub kind: IpyEscapeKind, -// pub value: Box, -// } - -// /// See also [BoolOp](https://docs.python.org/3/library/ast.html#ast.BoolOp) -// #[derive(Clone, Debug, PartialEq)] -// pub struct ExprBoolOp { -// pub range: TextRange, -// pub op: BoolOp, -// pub values: Vec, -// } - -// /// See also [NamedExpr](https://docs.python.org/3/library/ast.html#ast.NamedExpr) -// #[derive(Clone, Debug, PartialEq)] -// pub struct ExprNamed { -// pub range: TextRange, -// pub target: Box, -// pub value: Box, -// } - -// /// See also [BinOp](https://docs.python.org/3/library/ast.html#ast.BinOp) -// #[derive(Clone, Debug, PartialEq)] -// pub struct ExprBinOp { -// pub range: TextRange, -// pub left: Box, -// pub op: Operator, -// pub right: Box, -// } - -// /// See also [UnaryOp](https://docs.python.org/3/library/ast.html#ast.UnaryOp) -// #[derive(Clone, Debug, PartialEq)] -// pub struct ExprUnaryOp { -// pub range: TextRange, -// pub op: UnaryOp, -// pub operand: Box, -// } - -// /// See also [Lambda](https://docs.python.org/3/library/ast.html#ast.Lambda) -// #[derive(Clone, Debug, PartialEq)] -// pub struct ExprLambda { -// pub range: TextRange, -// pub parameters: Option>, -// pub body: Box, -// } - -// /// See also [IfExp](https://docs.python.org/3/library/ast.html#ast.IfExp) -// #[derive(Clone, Debug, PartialEq)] -// pub struct ExprIf { -// pub range: TextRange, -// pub test: Box, -// pub body: Box, -// pub orelse: Box, -// } - /// Represents an item in a [dictionary literal display][1]. /// /// Consider the following Python dictionary literal: @@ -500,13 +432,6 @@ impl Ranged for DictItem { } } -// /// See also [Dict](https://docs.python.org/3/library/ast.html#ast.Dict) -// #[derive(Clone, Debug, PartialEq)] -// pub struct ExprDict { -// pub range: TextRange, -// pub items: Vec, -// } - impl ExprDict { /// Returns an `Iterator` over the AST nodes representing the /// dictionary's keys. @@ -642,13 +567,6 @@ impl DoubleEndedIterator for DictValueIterator<'_> { impl FusedIterator for DictValueIterator<'_> {} impl ExactSizeIterator for DictValueIterator<'_> {} -// /// See also [Set](https://docs.python.org/3/library/ast.html#ast.Set) -// #[derive(Clone, Debug, PartialEq)] -// pub struct ExprSet { -// pub range: TextRange, -// pub elts: Vec, -// } - impl ExprSet { pub fn iter(&self) -> std::slice::Iter<'_, Expr> { self.elts.iter() @@ -672,78 +590,6 @@ impl<'a> IntoIterator for &'a ExprSet { } } -// /// See also [ListComp](https://docs.python.org/3/library/ast.html#ast.ListComp) -// #[derive(Clone, Debug, PartialEq)] -// pub struct ExprListComp { -// pub range: TextRange, -// pub elt: Box, -// pub generators: Vec, -// } - -// /// See also [SetComp](https://docs.python.org/3/library/ast.html#ast.SetComp) -// #[derive(Clone, Debug, PartialEq)] -// pub struct ExprSetComp { -// pub range: TextRange, -// pub elt: Box, -// pub generators: Vec, -// } - -// /// See also [DictComp](https://docs.python.org/3/library/ast.html#ast.DictComp) -// #[derive(Clone, Debug, PartialEq)] -// pub struct ExprDictComp { -// pub range: TextRange, -// pub key: Box, -// pub value: Box, -// pub generators: Vec, -// } - -// /// See also [GeneratorExp](https://docs.python.org/3/library/ast.html#ast.GeneratorExp) -// #[derive(Clone, Debug, PartialEq)] -// pub struct ExprGenerator { -// pub range: TextRange, -// pub elt: Box, -// pub generators: Vec, -// pub parenthesized: bool, -// } - -// /// See also [Await](https://docs.python.org/3/library/ast.html#ast.Await) -// #[derive(Clone, Debug, PartialEq)] -// pub struct ExprAwait { -// pub range: TextRange, -// pub value: Box, -// } - -// /// See also [Yield](https://docs.python.org/3/library/ast.html#ast.Yield) -// #[derive(Clone, Debug, PartialEq)] -// pub struct ExprYield { -// pub range: TextRange, -// pub value: Option>, -// } - -// /// See also [YieldFrom](https://docs.python.org/3/library/ast.html#ast.YieldFrom) -// #[derive(Clone, Debug, PartialEq)] -// pub struct ExprYieldFrom { -// pub range: TextRange, -// pub value: Box, -// } - -// /// See also [Compare](https://docs.python.org/3/library/ast.html#ast.Compare) -// #[derive(Clone, Debug, PartialEq)] -// pub struct ExprCompare { -// pub range: TextRange, -// pub left: Box, -// pub ops: Box<[CmpOp]>, -// pub comparators: Box<[Expr]>, -// } - -// /// See also [Call](https://docs.python.org/3/library/ast.html#ast.Call) -// #[derive(Clone, Debug, PartialEq)] -// pub struct ExprCall { -// pub range: TextRange, -// pub func: Box, -// pub arguments: Arguments, -// } - #[derive(Clone, Debug, PartialEq)] pub struct FStringFormatSpec { pub range: TextRange, @@ -816,20 +662,6 @@ pub struct DebugText { pub trailing: String, } -// /// An AST node that represents either a single-part f-string literal -// /// or an implicitly concatenated f-string literal. -// /// -// /// This type differs from the original Python AST ([JoinedStr]) in that it -// /// doesn't join the implicitly concatenated parts into a single string. Instead, -// /// it keeps them separate and provide various methods to access the parts. -// /// -// /// [JoinedStr]: https://docs.python.org/3/library/ast.html#ast.JoinedStr -// #[derive(Clone, Debug, PartialEq)] -// pub struct ExprFString { -// pub range: TextRange, -// pub value: FStringValue, -// } - impl ExprFString { /// Returns the single [`FString`] if the f-string isn't implicitly concatenated, [`None`] /// otherwise. @@ -1291,14 +1123,6 @@ impl fmt::Debug for FStringElements { } } -// /// An AST node that represents either a single-part string literal -// /// or an implicitly concatenated string literal. -// #[derive(Clone, Debug, PartialEq)] -// pub struct ExprStringLiteral { -// pub range: TextRange, -// pub value: StringLiteralValue, -// } - impl ExprStringLiteral { /// Return `Some(literal)` if the string only consists of a single `StringLiteral` part /// (indicating that it is not implicitly concatenated). Otherwise, return `None`. @@ -1743,14 +1567,6 @@ impl Debug for ConcatenatedStringLiteral { } } -// /// An AST node that represents either a single-part bytestring literal -// /// or an implicitly concatenated bytestring literal. -// #[derive(Clone, Debug, PartialEq)] -// pub struct ExprBytesLiteral { -// pub range: TextRange, -// pub value: BytesLiteralValue, -// } - impl ExprBytesLiteral { /// Return `Some(literal)` if the bytestring only consists of a single `BytesLiteral` part /// (indicating that it is not implicitly concatenated). Otherwise, return `None`. @@ -2352,12 +2168,6 @@ impl From for AnyStringFlags { } } -// #[derive(Clone, Debug, PartialEq)] -// pub struct ExprNumberLiteral { -// pub range: TextRange, -// pub value: Number, -// } - #[derive(Clone, Debug, PartialEq, is_macro::Is)] pub enum Number { Int(int::Int), @@ -2365,70 +2175,12 @@ pub enum Number { Complex { real: f64, imag: f64 }, } -// #[derive(Clone, Debug, Default, PartialEq)] -// pub struct ExprBooleanLiteral { -// pub range: TextRange, -// pub value: bool, -// } - -// #[derive(Clone, Debug, Default, PartialEq)] -// pub struct ExprNoneLiteral { -// pub range: TextRange, -// } - -// #[derive(Clone, Debug, Default, PartialEq)] -// pub struct ExprEllipsisLiteral { -// pub range: TextRange, -// } - -// /// See also [Attribute](https://docs.python.org/3/library/ast.html#ast.Attribute) -// #[derive(Clone, Debug, PartialEq)] -// pub struct ExprAttribute { -// pub range: TextRange, -// pub value: Box, -// pub attr: Identifier, -// pub ctx: ExprContext, -// } - -// /// See also [Subscript](https://docs.python.org/3/library/ast.html#ast.Subscript) -// #[derive(Clone, Debug, PartialEq)] -// pub struct ExprSubscript { -// pub range: TextRange, -// pub value: Box, -// pub slice: Box, -// pub ctx: ExprContext, -// } - -// /// See also [Starred](https://docs.python.org/3/library/ast.html#ast.Starred) -// #[derive(Clone, Debug, PartialEq)] -// pub struct ExprStarred { -// pub range: TextRange, -// pub value: Box, -// pub ctx: ExprContext, -// } - -// /// See also [Name](https://docs.python.org/3/library/ast.html#ast.Name) -// #[derive(Clone, Debug, PartialEq)] -// pub struct ExprName { -// pub range: TextRange, -// pub id: Name, -// pub ctx: ExprContext, -// } - impl ExprName { pub fn id(&self) -> &Name { &self.id } } -// /// See also [List](https://docs.python.org/3/library/ast.html#ast.List) -// #[derive(Clone, Debug, PartialEq)] -// pub struct ExprList { -// pub range: TextRange, -// pub elts: Vec, -// pub ctx: ExprContext, -// } - impl ExprList { pub fn iter(&self) -> std::slice::Iter<'_, Expr> { self.elts.iter() @@ -2452,17 +2204,6 @@ impl<'a> IntoIterator for &'a ExprList { } } -// /// See also [Tuple](https://docs.python.org/3/library/ast.html#ast.Tuple) -// #[derive(Clone, Debug, PartialEq)] -// pub struct ExprTuple { -// pub range: TextRange, -// pub elts: Vec, -// pub ctx: ExprContext, -// -// /// Whether the tuple is parenthesized in the source code. -// pub parenthesized: bool, -// } - impl ExprTuple { pub fn iter(&self) -> std::slice::Iter<'_, Expr> { self.elts.iter() @@ -2486,15 +2227,6 @@ impl<'a> IntoIterator for &'a ExprTuple { } } -// /// See also [Slice](https://docs.python.org/3/library/ast.html#ast.Slice) -// #[derive(Clone, Debug, PartialEq)] -// pub struct ExprSlice { -// pub range: TextRange, -// pub lower: Option>, -// pub upper: Option>, -// pub step: Option>, -// } - /// See also [expr_context](https://docs.python.org/3/library/ast.html#ast.expr_context) #[derive(Clone, Debug, PartialEq, is_macro::Is, Copy, Hash, Eq)] pub enum ExprContext {