Introduce an Arguments AST node for function calls and class definitions (#6259)

## Summary

This PR adds a new `Arguments` AST node, which we can use for function
calls and class definitions.

The `Arguments` node spans from the left (open) to right (close)
parentheses inclusive.

In the case of classes, the `Arguments` is an option, to differentiate
between:

```python
# None
class C: ...

# Some, with empty vectors
class C(): ...
```

In this PR, we don't really leverage this change (except that a few
rules get much simpler, since we don't need to lex to find the start and
end ranges of the parentheses, e.g.,
`crates/ruff/src/rules/pyupgrade/rules/lru_cache_without_parameters.rs`,
`crates/ruff/src/rules/pyupgrade/rules/unnecessary_class_parentheses.rs`).

In future PRs, this will be especially helpful for the formatter, since
we can track comments enclosed on the node itself.

## Test Plan

`cargo test`
This commit is contained in:
Charlie Marsh 2023-08-02 10:01:13 -04:00 committed by GitHub
parent 0d62ad2480
commit 981e64f82b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
107 changed files with 24258 additions and 23835 deletions

View file

@ -78,14 +78,18 @@ type FunctionArgument = (
);
// Parse arguments as supplied during a function/lambda *call*.
pub(crate) fn parse_args(func_args: Vec<FunctionArgument>) -> Result<ArgumentList, LexicalError> {
pub(crate) fn parse_arguments(
function_arguments: Vec<FunctionArgument>,
) -> Result<ArgumentList, LexicalError> {
let mut args = vec![];
let mut keywords = vec![];
let mut keyword_names =
FxHashSet::with_capacity_and_hasher(func_args.len(), BuildHasherDefault::default());
let mut keyword_names = FxHashSet::with_capacity_and_hasher(
function_arguments.len(),
BuildHasherDefault::default(),
);
let mut double_starred = false;
for (name, value) in func_args {
for (name, value) in function_arguments {
if let Some((start, end, name)) = name {
// Check for duplicate keyword arguments in the call.
if let Some(keyword_name) = &name {

View file

@ -9,7 +9,7 @@ use ruff_python_ast::{self as ast, Ranged, MagicKind};
use crate::{
Mode,
lexer::{LexicalError, LexicalErrorType},
function::{ArgumentList, parse_args, validate_pos_params, validate_arguments},
function::{ArgumentList, parse_arguments, validate_pos_params, validate_arguments},
context::set_context,
string::parse_strings,
token::{self, StringKind},
@ -1194,17 +1194,12 @@ KwargParameter<ParameterType>: Option<Box<ast::Parameter>> = {
};
ClassDef: ast::Stmt = {
<location:@L> <decorator_list:Decorator*> "class" <name:Identifier> <type_params:TypeParamList?> <a:("(" ArgumentList ")")?> ":" <body:Suite> => {
let (bases, keywords) = match a {
Some((_, arg, _)) => (arg.args, arg.keywords),
None => (vec![], vec![]),
};
<location:@L> <decorator_list:Decorator*> "class" <name:Identifier> <type_params:TypeParamList?> <arguments:Arguments?> ":" <body:Suite> => {
let end_location = body.last().unwrap().end();
ast::Stmt::ClassDef(
ast::StmtClassDef {
name,
bases,
keywords,
arguments,
body,
decorator_list,
type_params: type_params.unwrap_or_default(),
@ -1444,9 +1439,9 @@ AtomExpr<Goal>: ast::Expr = {
AtomExpr2<Goal>: ast::Expr = {
Atom<Goal>,
<location:@L> <f:AtomExpr2<"all">> "(" <a:ArgumentList> ")" <end_location:@R> => {
<location:@L> <f:AtomExpr2<"all">> <arguments:Arguments> <end_location:@R> => {
ast::Expr::Call(
ast::ExprCall { func: Box::new(f), args: a.args, keywords: a.keywords, range: (location..end_location).into() }
ast::ExprCall { func: Box::new(f), arguments, range: (location..end_location).into() }
)
},
<location:@L> <e:AtomExpr2<"all">> "[" <s:SubscriptList> "]" <end_location:@R> => ast::Expr::Subscript(
@ -1663,10 +1658,14 @@ SingleForComprehension: ast::Comprehension = {
ExpressionNoCond: ast::Expr = OrTest<"all">;
ComprehensionIf: ast::Expr = "if" <c:ExpressionNoCond> => c;
ArgumentList: ArgumentList = {
<e: Comma<FunctionArgument>> =>? {
let arg_list = parse_args(e)?;
Ok(arg_list)
Arguments: ast::Arguments = {
<location:@L> "(" <e: Comma<FunctionArgument>> ")" <end_location:@R> =>? {
let ArgumentList { args, keywords } = parse_arguments(e)?;
Ok(ast::Arguments {
args,
keywords,
range: (location..end_location).into()
})
}
};

File diff suppressed because it is too large Load diff

View file

@ -48,8 +48,7 @@ expression: parse_ast
id: "Abcd",
range: 59..63,
},
bases: [],
keywords: [],
arguments: None,
body: [
Pass(
StmtPass {

View file

@ -24,124 +24,127 @@ Call(
ctx: Load,
},
),
args: [
GeneratorExp(
ExprGeneratorExp {
range: 14..139,
elt: Name(
ExprName {
range: 14..17,
id: "sql",
ctx: Load,
},
),
generators: [
Comprehension {
range: 22..139,
target: Name(
ExprName {
range: 26..29,
id: "sql",
ctx: Store,
},
),
iter: Tuple(
ExprTuple {
range: 33..139,
elts: [
IfExp(
ExprIfExp {
range: 43..80,
test: Name(
ExprName {
range: 65..70,
id: "limit",
ctx: Load,
},
),
body: BinOp(
ExprBinOp {
range: 43..61,
left: Constant(
ExprConstant {
range: 43..53,
value: Str(
"LIMIT %d",
),
kind: None,
},
),
op: Mod,
right: Name(
ExprName {
range: 56..61,
id: "limit",
ctx: Load,
},
),
},
),
orelse: Constant(
ExprConstant {
range: 76..80,
value: None,
kind: None,
},
),
},
),
IfExp(
ExprIfExp {
range: 90..132,
test: Name(
ExprName {
range: 116..122,
id: "offset",
ctx: Load,
},
),
body: BinOp(
ExprBinOp {
range: 91..111,
left: Constant(
ExprConstant {
range: 91..102,
value: Str(
"OFFSET %d",
),
kind: None,
},
),
op: Mod,
right: Name(
ExprName {
range: 105..111,
id: "offset",
ctx: Load,
},
),
},
),
orelse: Constant(
ExprConstant {
range: 128..132,
value: None,
kind: None,
},
),
},
),
],
ctx: Load,
},
),
ifs: [],
is_async: false,
},
],
},
),
],
keywords: [],
arguments: Arguments {
range: 8..141,
args: [
GeneratorExp(
ExprGeneratorExp {
range: 14..139,
elt: Name(
ExprName {
range: 14..17,
id: "sql",
ctx: Load,
},
),
generators: [
Comprehension {
range: 22..139,
target: Name(
ExprName {
range: 26..29,
id: "sql",
ctx: Store,
},
),
iter: Tuple(
ExprTuple {
range: 33..139,
elts: [
IfExp(
ExprIfExp {
range: 43..80,
test: Name(
ExprName {
range: 65..70,
id: "limit",
ctx: Load,
},
),
body: BinOp(
ExprBinOp {
range: 43..61,
left: Constant(
ExprConstant {
range: 43..53,
value: Str(
"LIMIT %d",
),
kind: None,
},
),
op: Mod,
right: Name(
ExprName {
range: 56..61,
id: "limit",
ctx: Load,
},
),
},
),
orelse: Constant(
ExprConstant {
range: 76..80,
value: None,
kind: None,
},
),
},
),
IfExp(
ExprIfExp {
range: 90..132,
test: Name(
ExprName {
range: 116..122,
id: "offset",
ctx: Load,
},
),
body: BinOp(
ExprBinOp {
range: 91..111,
left: Constant(
ExprConstant {
range: 91..102,
value: Str(
"OFFSET %d",
),
kind: None,
},
),
op: Mod,
right: Name(
ExprName {
range: 105..111,
id: "offset",
ctx: Load,
},
),
},
),
orelse: Constant(
ExprConstant {
range: 128..132,
value: None,
kind: None,
},
),
},
),
],
ctx: Load,
},
),
ifs: [],
is_async: false,
},
],
},
),
],
keywords: [],
},
},
)

View file

@ -216,18 +216,21 @@ Module(
ctx: Load,
},
),
args: [
Constant(
ExprConstant {
range: 716..717,
value: Int(
5,
),
kind: None,
},
),
],
keywords: [],
arguments: Arguments {
range: 715..718,
args: [
Constant(
ExprConstant {
range: 716..717,
value: Int(
5,
),
kind: None,
},
),
],
keywords: [],
},
},
),
body: [

View file

@ -66,16 +66,19 @@ expression: parse_ast
ctx: Load,
},
),
args: [
Name(
ExprName {
range: 68..72,
id: "rest",
ctx: Load,
},
),
],
keywords: [],
arguments: Arguments {
range: 67..73,
args: [
Name(
ExprName {
range: 68..72,
id: "rest",
ctx: Load,
},
),
],
keywords: [],
},
},
),
},
@ -195,16 +198,19 @@ expression: parse_ast
ctx: Load,
},
),
args: [
Name(
ExprName {
range: 171..176,
id: "label",
ctx: Load,
},
),
],
keywords: [],
arguments: Arguments {
range: 170..177,
args: [
Name(
ExprName {
range: 171..176,
id: "label",
ctx: Load,
},
),
],
keywords: [],
},
},
),
},

View file

@ -122,42 +122,45 @@ expression: "parse_suite(source, \"<test>\").unwrap()"
ctx: Load,
},
),
args: [
Starred(
ExprStarred {
range: 93..99,
value: BinOp(
ExprBinOp {
range: 94..99,
left: Name(
ExprName {
range: 94..95,
id: "a",
ctx: Load,
},
),
op: Add,
right: Name(
ExprName {
range: 98..99,
id: "b",
ctx: Load,
},
),
},
),
ctx: Load,
},
),
Name(
ExprName {
range: 101..102,
id: "c",
ctx: Load,
},
),
],
keywords: [],
arguments: Arguments {
range: 92..103,
args: [
Starred(
ExprStarred {
range: 93..99,
value: BinOp(
ExprBinOp {
range: 94..99,
left: Name(
ExprName {
range: 94..95,
id: "a",
ctx: Load,
},
),
op: Add,
right: Name(
ExprName {
range: 98..99,
id: "b",
ctx: Load,
},
),
},
),
ctx: Load,
},
),
Name(
ExprName {
range: 101..102,
id: "c",
ctx: Load,
},
),
],
keywords: [],
},
},
),
},
@ -283,22 +286,25 @@ expression: "parse_suite(source, \"<test>\").unwrap()"
ctx: Load,
},
),
args: [
UnaryOp(
ExprUnaryOp {
range: 225..227,
op: USub,
operand: Name(
ExprName {
range: 226..227,
id: "a",
ctx: Load,
},
),
},
),
],
keywords: [],
arguments: Arguments {
range: 224..228,
args: [
UnaryOp(
ExprUnaryOp {
range: 225..227,
op: USub,
operand: Name(
ExprName {
range: 226..227,
id: "a",
ctx: Load,
},
),
},
),
],
keywords: [],
},
},
),
op: Mult,
@ -339,8 +345,11 @@ expression: "parse_suite(source, \"<test>\").unwrap()"
ctx: Load,
},
),
args: [],
keywords: [],
arguments: Arguments {
range: 270..272,
args: [],
keywords: [],
},
},
),
attr: Identifier {
@ -368,16 +377,19 @@ expression: "parse_suite(source, \"<test>\").unwrap()"
ctx: Load,
},
),
args: [
Tuple(
ExprTuple {
range: 298..300,
elts: [],
ctx: Load,
},
),
],
keywords: [],
arguments: Arguments {
range: 297..301,
args: [
Tuple(
ExprTuple {
range: 298..300,
elts: [],
ctx: Load,
},
),
],
keywords: [],
},
},
),
attr: Identifier {
@ -405,16 +417,19 @@ expression: "parse_suite(source, \"<test>\").unwrap()"
ctx: Load,
},
),
args: [
Tuple(
ExprTuple {
range: 329..331,
elts: [],
ctx: Load,
},
),
],
keywords: [],
arguments: Arguments {
range: 328..333,
args: [
Tuple(
ExprTuple {
range: 329..331,
elts: [],
ctx: Load,
},
),
],
keywords: [],
},
},
),
attr: Identifier {
@ -563,8 +578,11 @@ expression: "parse_suite(source, \"<test>\").unwrap()"
ctx: Load,
},
),
args: [],
keywords: [],
arguments: Arguments {
range: 476..478,
args: [],
keywords: [],
},
},
),
slice: Slice(
@ -771,33 +789,39 @@ expression: "parse_suite(source, \"<test>\").unwrap()"
ctx: Load,
},
),
args: [
Call(
ExprCall {
range: 626..635,
func: Name(
ExprName {
range: 626..631,
id: "match",
ctx: Load,
},
),
args: [
Constant(
ExprConstant {
range: 632..634,
value: Int(
12,
),
kind: None,
arguments: Arguments {
range: 625..636,
args: [
Call(
ExprCall {
range: 626..635,
func: Name(
ExprName {
range: 626..631,
id: "match",
ctx: Load,
},
),
],
keywords: [],
},
),
],
keywords: [],
arguments: Arguments {
range: 631..635,
args: [
Constant(
ExprConstant {
range: 632..634,
value: Int(
12,
),
kind: None,
},
),
],
keywords: [],
},
},
),
],
keywords: [],
},
},
),
},

View file

@ -1,6 +1,6 @@
---
source: crates/ruff_python_parser/src/parser.rs
expression: "ast::Suite::parse(source, \"<test>\").unwrap()"
expression: "parse_suite(source, \"<test>\").unwrap()"
---
[
Assign(
@ -37,8 +37,11 @@ expression: "ast::Suite::parse(source, \"<test>\").unwrap()"
ctx: Load,
},
),
args: [],
keywords: [],
arguments: Arguments {
range: 17..19,
args: [],
keywords: [],
},
},
),
},
@ -176,8 +179,11 @@ expression: "ast::Suite::parse(source, \"<test>\").unwrap()"
ctx: Load,
},
),
args: [],
keywords: [],
arguments: Arguments {
range: 88..90,
args: [],
keywords: [],
},
},
),
},
@ -249,8 +255,11 @@ expression: "ast::Suite::parse(source, \"<test>\").unwrap()"
ctx: Load,
},
),
args: [],
keywords: [],
arguments: Arguments {
range: 165..167,
args: [],
keywords: [],
},
},
),
},
@ -324,35 +333,41 @@ expression: "ast::Suite::parse(source, \"<test>\").unwrap()"
ctx: Load,
},
),
args: [
Call(
ExprCall {
range: 221..240,
func: Attribute(
ExprAttribute {
range: 221..238,
value: Constant(
ExprConstant {
range: 221..227,
value: Int(
11,
),
kind: None,
arguments: Arguments {
range: 220..241,
args: [
Call(
ExprCall {
range: 221..240,
func: Attribute(
ExprAttribute {
range: 221..238,
value: Constant(
ExprConstant {
range: 221..227,
value: Int(
11,
),
kind: None,
},
),
attr: Identifier {
id: "bit_length",
range: 228..238,
},
),
attr: Identifier {
id: "bit_length",
range: 228..238,
ctx: Load,
},
ctx: Load,
),
arguments: Arguments {
range: 238..240,
args: [],
keywords: [],
},
),
args: [],
keywords: [],
},
),
],
keywords: [],
},
),
],
keywords: [],
},
},
),
},
@ -391,8 +406,11 @@ expression: "ast::Suite::parse(source, \"<test>\").unwrap()"
ctx: Load,
},
),
args: [],
keywords: [],
arguments: Arguments {
range: 263..265,
args: [],
keywords: [],
},
},
),
},
@ -431,8 +449,11 @@ expression: "ast::Suite::parse(source, \"<test>\").unwrap()"
ctx: Load,
},
),
args: [],
keywords: [],
arguments: Arguments {
range: 287..289,
args: [],
keywords: [],
},
},
),
},
@ -504,8 +525,11 @@ expression: "ast::Suite::parse(source, \"<test>\").unwrap()"
ctx: Load,
},
),
args: [],
keywords: [],
arguments: Arguments {
range: 327..329,
args: [],
keywords: [],
},
},
),
},
@ -639,16 +663,19 @@ expression: "ast::Suite::parse(source, \"<test>\").unwrap()"
kind: None,
},
),
args: [
Name(
ExprName {
range: 388..390,
id: "no",
ctx: Load,
},
),
],
keywords: [],
arguments: Arguments {
range: 387..391,
args: [
Name(
ExprName {
range: 388..390,
id: "no",
ctx: Load,
},
),
],
keywords: [],
},
},
),
},

View file

@ -10,23 +10,28 @@ expression: "parse_suite(source, \"<test>\").unwrap()"
id: "Foo",
range: 6..9,
},
bases: [
Name(
ExprName {
range: 10..11,
id: "A",
ctx: Load,
},
),
Name(
ExprName {
range: 13..14,
id: "B",
ctx: Load,
},
),
],
keywords: [],
arguments: Some(
Arguments {
range: 9..15,
args: [
Name(
ExprName {
range: 10..11,
id: "A",
ctx: Load,
},
),
Name(
ExprName {
range: 13..14,
id: "B",
ctx: Load,
},
),
],
keywords: [],
},
),
body: [
FunctionDef(
StmtFunctionDef {

View file

@ -1,6 +1,6 @@
---
source: crates/ruff_python_parser/src/parser.rs
expression: "ast::Suite::parse(source, \"<test>\").unwrap()"
expression: "parse_suite(source, \"<test>\").unwrap()"
---
[
ClassDef(
@ -10,8 +10,13 @@ expression: "ast::Suite::parse(source, \"<test>\").unwrap()"
id: "Foo",
range: 16..19,
},
bases: [],
keywords: [],
arguments: Some(
Arguments {
range: 22..24,
args: [],
keywords: [],
},
),
body: [
Expr(
StmtExpr {
@ -48,8 +53,13 @@ expression: "ast::Suite::parse(source, \"<test>\").unwrap()"
id: "Foo",
range: 58..61,
},
bases: [],
keywords: [],
arguments: Some(
Arguments {
range: 69..71,
args: [],
keywords: [],
},
),
body: [
Expr(
StmtExpr {
@ -94,8 +104,13 @@ expression: "ast::Suite::parse(source, \"<test>\").unwrap()"
id: "Foo",
range: 111..114,
},
bases: [],
keywords: [],
arguments: Some(
Arguments {
range: 131..133,
args: [],
keywords: [],
},
),
body: [
Expr(
StmtExpr {
@ -155,8 +170,13 @@ expression: "ast::Suite::parse(source, \"<test>\").unwrap()"
id: "Foo",
range: 165..168,
},
bases: [],
keywords: [],
arguments: Some(
Arguments {
range: 174..176,
args: [],
keywords: [],
},
),
body: [
Expr(
StmtExpr {
@ -203,8 +223,13 @@ expression: "ast::Suite::parse(source, \"<test>\").unwrap()"
id: "Foo",
range: 206..209,
},
bases: [],
keywords: [],
arguments: Some(
Arguments {
range: 216..218,
args: [],
keywords: [],
},
),
body: [
Expr(
StmtExpr {
@ -251,8 +276,13 @@ expression: "ast::Suite::parse(source, \"<test>\").unwrap()"
id: "Foo",
range: 246..249,
},
bases: [],
keywords: [],
arguments: Some(
Arguments {
range: 254..256,
args: [],
keywords: [],
},
),
body: [
Expr(
StmtExpr {
@ -288,8 +318,13 @@ expression: "ast::Suite::parse(source, \"<test>\").unwrap()"
id: "Foo",
range: 281..284,
},
bases: [],
keywords: [],
arguments: Some(
Arguments {
range: 289..291,
args: [],
keywords: [],
},
),
body: [
Expr(
StmtExpr {
@ -325,8 +360,13 @@ expression: "ast::Suite::parse(source, \"<test>\").unwrap()"
id: "Foo",
range: 318..321,
},
bases: [],
keywords: [],
arguments: Some(
Arguments {
range: 341..343,
args: [],
keywords: [],
},
),
body: [
Pass(
StmtPass {

View file

@ -16,37 +16,40 @@ expression: parse_ast
ctx: Load,
},
),
args: [
Constant(
ExprConstant {
range: 8..20,
value: Str(
"positional",
),
kind: None,
},
),
],
keywords: [
Keyword {
range: 22..31,
arg: Some(
Identifier {
id: "keyword",
range: 22..29,
},
),
value: Constant(
arguments: Arguments {
range: 7..32,
args: [
Constant(
ExprConstant {
range: 30..31,
value: Int(
2,
range: 8..20,
value: Str(
"positional",
),
kind: None,
},
),
},
],
],
keywords: [
Keyword {
range: 22..31,
arg: Some(
Identifier {
id: "keyword",
range: 22..29,
},
),
value: Constant(
ExprConstant {
range: 30..31,
value: Int(
2,
),
kind: None,
},
),
},
],
},
},
),
},

View file

@ -16,27 +16,30 @@ expression: parse_ast
ctx: Load,
},
),
args: [
Constant(
ExprConstant {
range: 6..19,
value: Str(
"Hello world",
),
kind: None,
},
),
Constant(
ExprConstant {
range: 21..22,
value: Int(
2,
),
kind: None,
},
),
],
keywords: [],
arguments: Arguments {
range: 5..23,
args: [
Constant(
ExprConstant {
range: 6..19,
value: Str(
"Hello world",
),
kind: None,
},
),
Constant(
ExprConstant {
range: 21..22,
value: Int(
2,
),
kind: None,
},
),
],
keywords: [],
},
},
),
},

View file

@ -16,18 +16,21 @@ expression: parse_ast
ctx: Load,
},
),
args: [
Constant(
ExprConstant {
range: 6..19,
value: Str(
"Hello world",
),
kind: None,
},
),
],
keywords: [],
arguments: Arguments {
range: 5..20,
args: [
Constant(
ExprConstant {
range: 6..19,
value: Str(
"Hello world",
),
kind: None,
},
),
],
keywords: [],
},
},
),
},

View file

@ -1443,8 +1443,11 @@ expression: parse_ast
ctx: Load,
},
),
args: [],
keywords: [],
arguments: Arguments {
range: 1130..1132,
args: [],
keywords: [],
},
},
),
cases: [

View file

@ -21,18 +21,21 @@ expression: parse_ast
ctx: Load,
},
),
args: [
Constant(
ExprConstant {
range: 26..27,
value: Int(
1,
),
kind: None,
},
),
],
keywords: [],
arguments: Arguments {
range: 25..28,
args: [
Constant(
ExprConstant {
range: 26..27,
value: Int(
1,
),
kind: None,
},
),
],
keywords: [],
},
},
),
),
@ -73,55 +76,61 @@ expression: parse_ast
ctx: Load,
},
),
args: [
JoinedStr(
ExprJoinedStr {
range: 62..81,
values: [
Constant(
ExprConstant {
range: 64..71,
value: Str(
"caught ",
),
kind: None,
},
),
FormattedValue(
ExprFormattedValue {
range: 71..80,
value: Call(
ExprCall {
range: 72..79,
func: Name(
ExprName {
range: 72..76,
id: "type",
ctx: Load,
},
),
args: [
Name(
arguments: Arguments {
range: 61..82,
args: [
JoinedStr(
ExprJoinedStr {
range: 62..81,
values: [
Constant(
ExprConstant {
range: 64..71,
value: Str(
"caught ",
),
kind: None,
},
),
FormattedValue(
ExprFormattedValue {
range: 71..80,
value: Call(
ExprCall {
range: 72..79,
func: Name(
ExprName {
range: 77..78,
id: "e",
range: 72..76,
id: "type",
ctx: Load,
},
),
],
keywords: [],
},
),
debug_text: None,
conversion: None,
format_spec: None,
},
),
],
},
),
],
keywords: [],
arguments: Arguments {
range: 76..79,
args: [
Name(
ExprName {
range: 77..78,
id: "e",
ctx: Load,
},
),
],
keywords: [],
},
},
),
debug_text: None,
conversion: None,
format_spec: None,
},
),
],
},
),
],
keywords: [],
},
},
),
},
@ -161,55 +170,61 @@ expression: parse_ast
ctx: Load,
},
),
args: [
JoinedStr(
ExprJoinedStr {
range: 114..133,
values: [
Constant(
ExprConstant {
range: 116..123,
value: Str(
"caught ",
),
kind: None,
},
),
FormattedValue(
ExprFormattedValue {
range: 123..132,
value: Call(
ExprCall {
range: 124..131,
func: Name(
ExprName {
range: 124..128,
id: "type",
ctx: Load,
},
),
args: [
Name(
arguments: Arguments {
range: 113..134,
args: [
JoinedStr(
ExprJoinedStr {
range: 114..133,
values: [
Constant(
ExprConstant {
range: 116..123,
value: Str(
"caught ",
),
kind: None,
},
),
FormattedValue(
ExprFormattedValue {
range: 123..132,
value: Call(
ExprCall {
range: 124..131,
func: Name(
ExprName {
range: 129..130,
id: "e",
range: 124..128,
id: "type",
ctx: Load,
},
),
],
keywords: [],
},
),
debug_text: None,
conversion: None,
format_spec: None,
},
),
],
},
),
],
keywords: [],
arguments: Arguments {
range: 128..131,
args: [
Name(
ExprName {
range: 129..130,
id: "e",
ctx: Load,
},
),
],
keywords: [],
},
},
),
debug_text: None,
conversion: None,
format_spec: None,
},
),
],
},
),
],
keywords: [],
},
},
),
},

View file

@ -21,122 +21,137 @@ expression: parse_ast
ctx: Load,
},
),
args: [
Constant(
ExprConstant {
range: 30..34,
value: Str(
"eg",
),
kind: None,
},
),
List(
ExprList {
range: 44..97,
elts: [
Call(
ExprCall {
range: 45..58,
func: Name(
ExprName {
range: 45..55,
id: "ValueError",
ctx: Load,
},
),
args: [
Constant(
ExprConstant {
range: 56..57,
value: Int(
1,
),
kind: None,
arguments: Arguments {
range: 29..98,
args: [
Constant(
ExprConstant {
range: 30..34,
value: Str(
"eg",
),
kind: None,
},
),
List(
ExprList {
range: 44..97,
elts: [
Call(
ExprCall {
range: 45..58,
func: Name(
ExprName {
range: 45..55,
id: "ValueError",
ctx: Load,
},
),
],
keywords: [],
},
),
Call(
ExprCall {
range: 60..72,
func: Name(
ExprName {
range: 60..69,
id: "TypeError",
ctx: Load,
},
),
args: [
Constant(
ExprConstant {
range: 70..71,
value: Int(
2,
arguments: Arguments {
range: 55..58,
args: [
Constant(
ExprConstant {
range: 56..57,
value: Int(
1,
),
kind: None,
},
),
kind: None,
],
keywords: [],
},
},
),
Call(
ExprCall {
range: 60..72,
func: Name(
ExprName {
range: 60..69,
id: "TypeError",
ctx: Load,
},
),
],
keywords: [],
},
),
Call(
ExprCall {
range: 74..84,
func: Name(
ExprName {
range: 74..81,
id: "OSError",
ctx: Load,
},
),
args: [
Constant(
ExprConstant {
range: 82..83,
value: Int(
3,
arguments: Arguments {
range: 69..72,
args: [
Constant(
ExprConstant {
range: 70..71,
value: Int(
2,
),
kind: None,
},
),
kind: None,
],
keywords: [],
},
},
),
Call(
ExprCall {
range: 74..84,
func: Name(
ExprName {
range: 74..81,
id: "OSError",
ctx: Load,
},
),
],
keywords: [],
},
),
Call(
ExprCall {
range: 86..96,
func: Name(
ExprName {
range: 86..93,
id: "OSError",
ctx: Load,
},
),
args: [
Constant(
ExprConstant {
range: 94..95,
value: Int(
4,
arguments: Arguments {
range: 81..84,
args: [
Constant(
ExprConstant {
range: 82..83,
value: Int(
3,
),
kind: None,
},
),
kind: None,
],
keywords: [],
},
},
),
Call(
ExprCall {
range: 86..96,
func: Name(
ExprName {
range: 86..93,
id: "OSError",
ctx: Load,
},
),
],
keywords: [],
},
),
],
ctx: Load,
},
),
],
keywords: [],
arguments: Arguments {
range: 93..96,
args: [
Constant(
ExprConstant {
range: 94..95,
value: Int(
4,
),
kind: None,
},
),
],
keywords: [],
},
},
),
],
ctx: Load,
},
),
],
keywords: [],
},
},
),
),
@ -177,89 +192,95 @@ expression: parse_ast
ctx: Load,
},
),
args: [
JoinedStr(
ExprJoinedStr {
range: 133..179,
values: [
Constant(
ExprConstant {
range: 135..142,
value: Str(
"caught ",
),
kind: None,
},
),
FormattedValue(
ExprFormattedValue {
range: 142..151,
value: Call(
ExprCall {
range: 143..150,
func: Name(
ExprName {
range: 143..147,
id: "type",
ctx: Load,
},
),
args: [
Name(
arguments: Arguments {
range: 132..180,
args: [
JoinedStr(
ExprJoinedStr {
range: 133..179,
values: [
Constant(
ExprConstant {
range: 135..142,
value: Str(
"caught ",
),
kind: None,
},
),
FormattedValue(
ExprFormattedValue {
range: 142..151,
value: Call(
ExprCall {
range: 143..150,
func: Name(
ExprName {
range: 148..149,
range: 143..147,
id: "type",
ctx: Load,
},
),
arguments: Arguments {
range: 147..150,
args: [
Name(
ExprName {
range: 148..149,
id: "e",
ctx: Load,
},
),
],
keywords: [],
},
},
),
debug_text: None,
conversion: None,
format_spec: None,
},
),
Constant(
ExprConstant {
range: 151..164,
value: Str(
" with nested ",
),
kind: None,
},
),
FormattedValue(
ExprFormattedValue {
range: 164..178,
value: Attribute(
ExprAttribute {
range: 165..177,
value: Name(
ExprName {
range: 165..166,
id: "e",
ctx: Load,
},
),
],
keywords: [],
},
),
debug_text: None,
conversion: None,
format_spec: None,
},
),
Constant(
ExprConstant {
range: 151..164,
value: Str(
" with nested ",
),
kind: None,
},
),
FormattedValue(
ExprFormattedValue {
range: 164..178,
value: Attribute(
ExprAttribute {
range: 165..177,
value: Name(
ExprName {
range: 165..166,
id: "e",
ctx: Load,
attr: Identifier {
id: "exceptions",
range: 167..177,
},
),
attr: Identifier {
id: "exceptions",
range: 167..177,
ctx: Load,
},
ctx: Load,
},
),
debug_text: None,
conversion: None,
format_spec: None,
},
),
],
},
),
],
keywords: [],
),
debug_text: None,
conversion: None,
format_spec: None,
},
),
],
},
),
],
keywords: [],
},
},
),
},
@ -299,89 +320,95 @@ expression: parse_ast
ctx: Load,
},
),
args: [
JoinedStr(
ExprJoinedStr {
range: 213..259,
values: [
Constant(
ExprConstant {
range: 215..222,
value: Str(
"caught ",
),
kind: None,
},
),
FormattedValue(
ExprFormattedValue {
range: 222..231,
value: Call(
ExprCall {
range: 223..230,
func: Name(
ExprName {
range: 223..227,
id: "type",
ctx: Load,
},
),
args: [
Name(
arguments: Arguments {
range: 212..260,
args: [
JoinedStr(
ExprJoinedStr {
range: 213..259,
values: [
Constant(
ExprConstant {
range: 215..222,
value: Str(
"caught ",
),
kind: None,
},
),
FormattedValue(
ExprFormattedValue {
range: 222..231,
value: Call(
ExprCall {
range: 223..230,
func: Name(
ExprName {
range: 228..229,
range: 223..227,
id: "type",
ctx: Load,
},
),
arguments: Arguments {
range: 227..230,
args: [
Name(
ExprName {
range: 228..229,
id: "e",
ctx: Load,
},
),
],
keywords: [],
},
},
),
debug_text: None,
conversion: None,
format_spec: None,
},
),
Constant(
ExprConstant {
range: 231..244,
value: Str(
" with nested ",
),
kind: None,
},
),
FormattedValue(
ExprFormattedValue {
range: 244..258,
value: Attribute(
ExprAttribute {
range: 245..257,
value: Name(
ExprName {
range: 245..246,
id: "e",
ctx: Load,
},
),
],
keywords: [],
},
),
debug_text: None,
conversion: None,
format_spec: None,
},
),
Constant(
ExprConstant {
range: 231..244,
value: Str(
" with nested ",
),
kind: None,
},
),
FormattedValue(
ExprFormattedValue {
range: 244..258,
value: Attribute(
ExprAttribute {
range: 245..257,
value: Name(
ExprName {
range: 245..246,
id: "e",
ctx: Load,
attr: Identifier {
id: "exceptions",
range: 247..257,
},
),
attr: Identifier {
id: "exceptions",
range: 247..257,
ctx: Load,
},
ctx: Load,
},
),
debug_text: None,
conversion: None,
format_spec: None,
},
),
],
},
),
],
keywords: [],
),
debug_text: None,
conversion: None,
format_spec: None,
},
),
],
},
),
],
keywords: [],
},
},
),
},

View file

@ -122,42 +122,45 @@ expression: "parse_suite(source, \"<test>\").unwrap()"
ctx: Load,
},
),
args: [
Starred(
ExprStarred {
range: 88..94,
value: BinOp(
ExprBinOp {
range: 89..94,
left: Name(
ExprName {
range: 89..90,
id: "a",
ctx: Load,
},
),
op: Add,
right: Name(
ExprName {
range: 93..94,
id: "b",
ctx: Load,
},
),
},
),
ctx: Load,
},
),
Name(
ExprName {
range: 96..97,
id: "c",
ctx: Load,
},
),
],
keywords: [],
arguments: Arguments {
range: 87..98,
args: [
Starred(
ExprStarred {
range: 88..94,
value: BinOp(
ExprBinOp {
range: 89..94,
left: Name(
ExprName {
range: 89..90,
id: "a",
ctx: Load,
},
),
op: Add,
right: Name(
ExprName {
range: 93..94,
id: "b",
ctx: Load,
},
),
},
),
ctx: Load,
},
),
Name(
ExprName {
range: 96..97,
id: "c",
ctx: Load,
},
),
],
keywords: [],
},
},
),
},
@ -283,22 +286,25 @@ expression: "parse_suite(source, \"<test>\").unwrap()"
ctx: Load,
},
),
args: [
UnaryOp(
ExprUnaryOp {
range: 214..216,
op: USub,
operand: Name(
ExprName {
range: 215..216,
id: "a",
ctx: Load,
},
),
},
),
],
keywords: [],
arguments: Arguments {
range: 213..217,
args: [
UnaryOp(
ExprUnaryOp {
range: 214..216,
op: USub,
operand: Name(
ExprName {
range: 215..216,
id: "a",
ctx: Load,
},
),
},
),
],
keywords: [],
},
},
),
op: Mult,
@ -339,8 +345,11 @@ expression: "parse_suite(source, \"<test>\").unwrap()"
ctx: Load,
},
),
args: [],
keywords: [],
arguments: Arguments {
range: 257..259,
args: [],
keywords: [],
},
},
),
attr: Identifier {
@ -368,16 +377,19 @@ expression: "parse_suite(source, \"<test>\").unwrap()"
ctx: Load,
},
),
args: [
Tuple(
ExprTuple {
range: 283..285,
elts: [],
ctx: Load,
},
),
],
keywords: [],
arguments: Arguments {
range: 282..286,
args: [
Tuple(
ExprTuple {
range: 283..285,
elts: [],
ctx: Load,
},
),
],
keywords: [],
},
},
),
attr: Identifier {
@ -405,16 +417,19 @@ expression: "parse_suite(source, \"<test>\").unwrap()"
ctx: Load,
},
),
args: [
Tuple(
ExprTuple {
range: 312..314,
elts: [],
ctx: Load,
},
),
],
keywords: [],
arguments: Arguments {
range: 311..316,
args: [
Tuple(
ExprTuple {
range: 312..314,
elts: [],
ctx: Load,
},
),
],
keywords: [],
},
},
),
attr: Identifier {
@ -563,8 +578,11 @@ expression: "parse_suite(source, \"<test>\").unwrap()"
ctx: Load,
},
),
args: [],
keywords: [],
arguments: Arguments {
range: 450..452,
args: [],
keywords: [],
},
},
),
slice: Slice(
@ -707,33 +725,39 @@ expression: "parse_suite(source, \"<test>\").unwrap()"
ctx: Load,
},
),
args: [
Call(
ExprCall {
range: 542..550,
func: Name(
ExprName {
range: 542..546,
id: "type",
ctx: Load,
},
),
args: [
Constant(
ExprConstant {
range: 547..549,
value: Int(
12,
),
kind: None,
arguments: Arguments {
range: 541..551,
args: [
Call(
ExprCall {
range: 542..550,
func: Name(
ExprName {
range: 542..546,
id: "type",
ctx: Load,
},
),
],
keywords: [],
},
),
],
keywords: [],
arguments: Arguments {
range: 546..550,
args: [
Constant(
ExprConstant {
range: 547..549,
value: Int(
12,
),
kind: None,
},
),
],
keywords: [],
},
},
),
],
keywords: [],
},
},
),
},
@ -751,16 +775,19 @@ expression: "parse_suite(source, \"<test>\").unwrap()"
ctx: Load,
},
),
args: [
Name(
ExprName {
range: 557..561,
id: "type",
ctx: Load,
},
),
],
keywords: [],
arguments: Arguments {
range: 556..562,
args: [
Name(
ExprName {
range: 557..561,
id: "type",
ctx: Load,
},
),
],
keywords: [],
},
},
),
},
@ -825,16 +852,19 @@ expression: "parse_suite(source, \"<test>\").unwrap()"
ctx: Load,
},
),
args: [
Name(
ExprName {
range: 594..595,
id: "b",
ctx: Load,
},
),
],
keywords: [],
arguments: Arguments {
range: 593..596,
args: [
Name(
ExprName {
range: 594..595,
id: "b",
ctx: Load,
},
),
],
keywords: [],
},
},
),
},
@ -852,25 +882,28 @@ expression: "parse_suite(source, \"<test>\").unwrap()"
ctx: Load,
},
),
args: [],
keywords: [
Keyword {
range: 607..614,
arg: Some(
Identifier {
id: "X",
range: 607..608,
},
),
value: Name(
ExprName {
range: 611..614,
id: "int",
ctx: Load,
},
),
},
],
arguments: Arguments {
range: 604..616,
args: [],
keywords: [
Keyword {
range: 607..614,
arg: Some(
Identifier {
id: "X",
range: 607..608,
},
),
value: Name(
ExprName {
range: 611..614,
id: "int",
ctx: Load,
},
),
},
],
},
},
),
},