Skip to content

Commit

Permalink
Remove commented out inline tests (#10857)
Browse files Browse the repository at this point in the history
## Summary

This PR removes a couple of inline tests TODO which was a leftover from
#10809
  • Loading branch information
dhruvmanila committed Apr 17, 2024
1 parent dec4387 commit ce687f5
Show file tree
Hide file tree
Showing 9 changed files with 575 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
assert False, *x
assert False, assert x
assert False, yield x
assert False, x := 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
assert *x
assert assert x
assert yield x
assert x := 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
raise x from *y
raise x from yield y
raise x from y := 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
raise *x
raise yield x
raise x := 1
4 changes: 0 additions & 4 deletions crates/ruff_python_parser/src/parser/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,6 @@ impl<'src> Parser<'src> {
let exc = if self.at(TokenKind::Newline) {
None
} else {
// TODO(dhruvmanila): Disallow starred and yield expression
// test_err raise_stmt_invalid_exc
// raise *x
// raise yield x
Expand All @@ -358,7 +357,6 @@ impl<'src> Parser<'src> {
};

let cause = (exc.is_some() && self.eat(TokenKind::From)).then(|| {
// TODO(dhruvmanila): Disallow starred and yield expression
// test_err raise_stmt_invalid_cause
// raise x from *y
// raise x from yield y
Expand Down Expand Up @@ -659,7 +657,6 @@ impl<'src> Parser<'src> {
// test_err assert_empty_test
// assert

// TODO(dhruvmanila): Disallow starred and yield expression
// test_err assert_invalid_test_expr
// assert *x
// assert assert x
Expand All @@ -669,7 +666,6 @@ impl<'src> Parser<'src> {

let msg = if self.eat(TokenKind::Comma) {
if self.at_expr() {
// TODO(dhruvmanila): Disallow starred and yield expression
// test_err assert_invalid_msg_expr
// assert False, *x
// assert False, assert x
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/inline/err/assert_invalid_msg_expr.py
---
## AST

```
Module(
ModModule {
range: 0..83,
body: [
Assert(
StmtAssert {
range: 0..16,
test: BooleanLiteral(
ExprBooleanLiteral {
range: 7..12,
value: false,
},
),
msg: Some(
Starred(
ExprStarred {
range: 14..16,
value: Name(
ExprName {
range: 15..16,
id: "x",
ctx: Load,
},
),
ctx: Load,
},
),
),
},
),
Assert(
StmtAssert {
range: 17..30,
test: BooleanLiteral(
ExprBooleanLiteral {
range: 24..29,
value: false,
},
),
msg: None,
},
),
Assert(
StmtAssert {
range: 31..39,
test: Name(
ExprName {
range: 38..39,
id: "x",
ctx: Load,
},
),
msg: None,
},
),
Assert(
StmtAssert {
range: 40..61,
test: BooleanLiteral(
ExprBooleanLiteral {
range: 47..52,
value: false,
},
),
msg: Some(
Yield(
ExprYield {
range: 54..61,
value: Some(
Name(
ExprName {
range: 60..61,
id: "x",
ctx: Load,
},
),
),
},
),
),
},
),
Assert(
StmtAssert {
range: 62..77,
test: BooleanLiteral(
ExprBooleanLiteral {
range: 69..74,
value: false,
},
),
msg: Some(
Name(
ExprName {
range: 76..77,
id: "x",
ctx: Load,
},
),
),
},
),
Expr(
StmtExpr {
range: 81..82,
value: NumberLiteral(
ExprNumberLiteral {
range: 81..82,
value: Int(
1,
),
},
),
},
),
],
},
)
```
## Errors

|
1 | assert False, *x
| ^^ Syntax Error: starred expression cannot be used here
2 | assert False, assert x
3 | assert False, yield x
|


|
1 | assert False, *x
2 | assert False, assert x
| ^^^^^^ Syntax Error: Expected an expression
3 | assert False, yield x
4 | assert False, x := 1
|


|
1 | assert False, *x
2 | assert False, assert x
| ^^^^^^^^^^^^^^^^^^^^ Syntax Error: use `;` to separate simple statements
3 | assert False, yield x
4 | assert False, x := 1
|


|
1 | assert False, *x
2 | assert False, assert x
3 | assert False, yield x
| ^^^^^^^ Syntax Error: yield expression cannot be used here
4 | assert False, x := 1
|


|
2 | assert False, assert x
3 | assert False, yield x
4 | assert False, x := 1
| ^^ Syntax Error: Expected a statement
|
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
---
source: crates/ruff_python_parser/tests/fixtures.rs
input_file: crates/ruff_python_parser/resources/inline/err/assert_invalid_test_expr.py
---
## AST

```
Module(
ModModule {
range: 0..55,
body: [
Assert(
StmtAssert {
range: 0..9,
test: Starred(
ExprStarred {
range: 7..9,
value: Name(
ExprName {
range: 8..9,
id: "x",
ctx: Load,
},
),
ctx: Load,
},
),
msg: None,
},
),
Assert(
StmtAssert {
range: 10..23,
test: Name(
ExprName {
range: 17..23,
id: "assert",
ctx: Load,
},
),
msg: None,
},
),
Expr(
StmtExpr {
range: 24..25,
value: Name(
ExprName {
range: 24..25,
id: "x",
ctx: Load,
},
),
},
),
Assert(
StmtAssert {
range: 26..40,
test: Yield(
ExprYield {
range: 33..40,
value: Some(
Name(
ExprName {
range: 39..40,
id: "x",
ctx: Load,
},
),
),
},
),
msg: None,
},
),
Assert(
StmtAssert {
range: 41..49,
test: Name(
ExprName {
range: 48..49,
id: "x",
ctx: Load,
},
),
msg: None,
},
),
Expr(
StmtExpr {
range: 53..54,
value: NumberLiteral(
ExprNumberLiteral {
range: 53..54,
value: Int(
1,
),
},
),
},
),
],
},
)
```
## Errors

|
1 | assert *x
| ^^ Syntax Error: starred expression cannot be used here
2 | assert assert x
3 | assert yield x
|


|
1 | assert *x
2 | assert assert x
| ^^^^^^ Syntax Error: Expected an identifier, but found a keyword 'assert' that cannot be used here
3 | assert yield x
4 | assert x := 1
|


|
1 | assert *x
2 | assert assert x
| ^^^^^^^^^^^^^^^ Syntax Error: use `;` to separate simple statements
3 | assert yield x
4 | assert x := 1
|


|
1 | assert *x
2 | assert assert x
3 | assert yield x
| ^^^^^^^ Syntax Error: yield expression cannot be used here
4 | assert x := 1
|


|
2 | assert assert x
3 | assert yield x
4 | assert x := 1
| ^^ Syntax Error: Expected a statement
|
Loading

0 comments on commit ce687f5

Please sign in to comment.