mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 18:58:04 +00:00
Make syntax error for unparenthesized except tuples version specific to before 3.14 (#17660)
What it says on the tin 😄
This commit is contained in:
parent
31e6576971
commit
3c460a7b9a
9 changed files with 526 additions and 274 deletions
|
@ -1,251 +0,0 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
||||
input_file: crates/ruff_python_parser/resources/inline/err/except_stmt_unparenthesized_tuple.py
|
||||
snapshot_kind: text
|
||||
---
|
||||
## AST
|
||||
|
||||
```
|
||||
Module(
|
||||
ModModule {
|
||||
range: 0..131,
|
||||
body: [
|
||||
Try(
|
||||
StmtTry {
|
||||
range: 0..64,
|
||||
body: [
|
||||
Pass(
|
||||
StmtPass {
|
||||
range: 9..13,
|
||||
},
|
||||
),
|
||||
],
|
||||
handlers: [
|
||||
ExceptHandler(
|
||||
ExceptHandlerExceptHandler {
|
||||
range: 14..35,
|
||||
type_: Some(
|
||||
Tuple(
|
||||
ExprTuple {
|
||||
range: 21..25,
|
||||
elts: [
|
||||
Name(
|
||||
ExprName {
|
||||
range: 21..22,
|
||||
id: Name("x"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
Name(
|
||||
ExprName {
|
||||
range: 24..25,
|
||||
id: Name("y"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
],
|
||||
ctx: Load,
|
||||
parenthesized: false,
|
||||
},
|
||||
),
|
||||
),
|
||||
name: None,
|
||||
body: [
|
||||
Pass(
|
||||
StmtPass {
|
||||
range: 31..35,
|
||||
},
|
||||
),
|
||||
],
|
||||
},
|
||||
),
|
||||
ExceptHandler(
|
||||
ExceptHandlerExceptHandler {
|
||||
range: 36..64,
|
||||
type_: Some(
|
||||
Tuple(
|
||||
ExprTuple {
|
||||
range: 43..47,
|
||||
elts: [
|
||||
Name(
|
||||
ExprName {
|
||||
range: 43..44,
|
||||
id: Name("x"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
Name(
|
||||
ExprName {
|
||||
range: 46..47,
|
||||
id: Name("y"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
],
|
||||
ctx: Load,
|
||||
parenthesized: false,
|
||||
},
|
||||
),
|
||||
),
|
||||
name: Some(
|
||||
Identifier {
|
||||
id: Name("exc"),
|
||||
range: 51..54,
|
||||
},
|
||||
),
|
||||
body: [
|
||||
Pass(
|
||||
StmtPass {
|
||||
range: 60..64,
|
||||
},
|
||||
),
|
||||
],
|
||||
},
|
||||
),
|
||||
],
|
||||
orelse: [],
|
||||
finalbody: [],
|
||||
is_star: false,
|
||||
},
|
||||
),
|
||||
Try(
|
||||
StmtTry {
|
||||
range: 65..130,
|
||||
body: [
|
||||
Pass(
|
||||
StmtPass {
|
||||
range: 74..78,
|
||||
},
|
||||
),
|
||||
],
|
||||
handlers: [
|
||||
ExceptHandler(
|
||||
ExceptHandlerExceptHandler {
|
||||
range: 79..101,
|
||||
type_: Some(
|
||||
Tuple(
|
||||
ExprTuple {
|
||||
range: 87..91,
|
||||
elts: [
|
||||
Name(
|
||||
ExprName {
|
||||
range: 87..88,
|
||||
id: Name("x"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
Name(
|
||||
ExprName {
|
||||
range: 90..91,
|
||||
id: Name("y"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
],
|
||||
ctx: Load,
|
||||
parenthesized: false,
|
||||
},
|
||||
),
|
||||
),
|
||||
name: None,
|
||||
body: [
|
||||
Pass(
|
||||
StmtPass {
|
||||
range: 97..101,
|
||||
},
|
||||
),
|
||||
],
|
||||
},
|
||||
),
|
||||
ExceptHandler(
|
||||
ExceptHandlerExceptHandler {
|
||||
range: 102..130,
|
||||
type_: Some(
|
||||
Tuple(
|
||||
ExprTuple {
|
||||
range: 110..114,
|
||||
elts: [
|
||||
Name(
|
||||
ExprName {
|
||||
range: 110..111,
|
||||
id: Name("x"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
Name(
|
||||
ExprName {
|
||||
range: 113..114,
|
||||
id: Name("y"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
],
|
||||
ctx: Load,
|
||||
parenthesized: false,
|
||||
},
|
||||
),
|
||||
),
|
||||
name: Some(
|
||||
Identifier {
|
||||
id: Name("eg"),
|
||||
range: 118..120,
|
||||
},
|
||||
),
|
||||
body: [
|
||||
Pass(
|
||||
StmtPass {
|
||||
range: 126..130,
|
||||
},
|
||||
),
|
||||
],
|
||||
},
|
||||
),
|
||||
],
|
||||
orelse: [],
|
||||
finalbody: [],
|
||||
is_star: true,
|
||||
},
|
||||
),
|
||||
],
|
||||
},
|
||||
)
|
||||
```
|
||||
## Errors
|
||||
|
||||
|
|
||||
1 | try:
|
||||
2 | pass
|
||||
3 | except x, y:
|
||||
| ^^^^ Syntax Error: Multiple exception types must be parenthesized
|
||||
4 | pass
|
||||
5 | except x, y as exc:
|
||||
|
|
||||
|
||||
|
||||
|
|
||||
3 | except x, y:
|
||||
4 | pass
|
||||
5 | except x, y as exc:
|
||||
| ^^^^ Syntax Error: Multiple exception types must be parenthesized
|
||||
6 | pass
|
||||
7 | try:
|
||||
|
|
||||
|
||||
|
||||
|
|
||||
7 | try:
|
||||
8 | pass
|
||||
9 | except* x, y:
|
||||
| ^^^^ Syntax Error: Multiple exception types must be parenthesized
|
||||
10 | pass
|
||||
11 | except* x, y as eg:
|
||||
|
|
||||
|
||||
|
||||
|
|
||||
9 | except* x, y:
|
||||
10 | pass
|
||||
11 | except* x, y as eg:
|
||||
| ^^^^ Syntax Error: Multiple exception types must be parenthesized
|
||||
12 | pass
|
||||
|
|
|
@ -0,0 +1,154 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
||||
input_file: crates/ruff_python_parser/resources/inline/err/except_stmt_unparenthesized_tuple_as.py
|
||||
---
|
||||
## AST
|
||||
|
||||
```
|
||||
Module(
|
||||
ModModule {
|
||||
range: 0..86,
|
||||
body: [
|
||||
Try(
|
||||
StmtTry {
|
||||
range: 0..42,
|
||||
body: [
|
||||
Pass(
|
||||
StmtPass {
|
||||
range: 9..13,
|
||||
},
|
||||
),
|
||||
],
|
||||
handlers: [
|
||||
ExceptHandler(
|
||||
ExceptHandlerExceptHandler {
|
||||
range: 14..42,
|
||||
type_: Some(
|
||||
Tuple(
|
||||
ExprTuple {
|
||||
range: 21..25,
|
||||
elts: [
|
||||
Name(
|
||||
ExprName {
|
||||
range: 21..22,
|
||||
id: Name("x"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
Name(
|
||||
ExprName {
|
||||
range: 24..25,
|
||||
id: Name("y"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
],
|
||||
ctx: Load,
|
||||
parenthesized: false,
|
||||
},
|
||||
),
|
||||
),
|
||||
name: Some(
|
||||
Identifier {
|
||||
id: Name("exc"),
|
||||
range: 29..32,
|
||||
},
|
||||
),
|
||||
body: [
|
||||
Pass(
|
||||
StmtPass {
|
||||
range: 38..42,
|
||||
},
|
||||
),
|
||||
],
|
||||
},
|
||||
),
|
||||
],
|
||||
orelse: [],
|
||||
finalbody: [],
|
||||
is_star: false,
|
||||
},
|
||||
),
|
||||
Try(
|
||||
StmtTry {
|
||||
range: 43..85,
|
||||
body: [
|
||||
Pass(
|
||||
StmtPass {
|
||||
range: 52..56,
|
||||
},
|
||||
),
|
||||
],
|
||||
handlers: [
|
||||
ExceptHandler(
|
||||
ExceptHandlerExceptHandler {
|
||||
range: 57..85,
|
||||
type_: Some(
|
||||
Tuple(
|
||||
ExprTuple {
|
||||
range: 65..69,
|
||||
elts: [
|
||||
Name(
|
||||
ExprName {
|
||||
range: 65..66,
|
||||
id: Name("x"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
Name(
|
||||
ExprName {
|
||||
range: 68..69,
|
||||
id: Name("y"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
],
|
||||
ctx: Load,
|
||||
parenthesized: false,
|
||||
},
|
||||
),
|
||||
),
|
||||
name: Some(
|
||||
Identifier {
|
||||
id: Name("eg"),
|
||||
range: 73..75,
|
||||
},
|
||||
),
|
||||
body: [
|
||||
Pass(
|
||||
StmtPass {
|
||||
range: 81..85,
|
||||
},
|
||||
),
|
||||
],
|
||||
},
|
||||
),
|
||||
],
|
||||
orelse: [],
|
||||
finalbody: [],
|
||||
is_star: true,
|
||||
},
|
||||
),
|
||||
],
|
||||
},
|
||||
)
|
||||
```
|
||||
## Errors
|
||||
|
||||
|
|
||||
1 | try:
|
||||
2 | pass
|
||||
3 | except x, y as exc:
|
||||
| ^^^^ Syntax Error: Multiple exception types must be parenthesized when using `as`
|
||||
4 | pass
|
||||
5 | try:
|
||||
|
|
||||
|
||||
|
||||
|
|
||||
5 | try:
|
||||
6 | pass
|
||||
7 | except* x, y as eg:
|
||||
| ^^^^ Syntax Error: Multiple exception types must be parenthesized when using `as`
|
||||
8 | pass
|
||||
|
|
|
@ -0,0 +1,144 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
||||
input_file: crates/ruff_python_parser/resources/inline/err/except_stmt_unparenthesized_tuple_no_as_py313.py
|
||||
---
|
||||
## AST
|
||||
|
||||
```
|
||||
Module(
|
||||
ModModule {
|
||||
range: 0..117,
|
||||
body: [
|
||||
Try(
|
||||
StmtTry {
|
||||
range: 44..79,
|
||||
body: [
|
||||
Pass(
|
||||
StmtPass {
|
||||
range: 53..57,
|
||||
},
|
||||
),
|
||||
],
|
||||
handlers: [
|
||||
ExceptHandler(
|
||||
ExceptHandlerExceptHandler {
|
||||
range: 58..79,
|
||||
type_: Some(
|
||||
Tuple(
|
||||
ExprTuple {
|
||||
range: 65..69,
|
||||
elts: [
|
||||
Name(
|
||||
ExprName {
|
||||
range: 65..66,
|
||||
id: Name("x"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
Name(
|
||||
ExprName {
|
||||
range: 68..69,
|
||||
id: Name("y"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
],
|
||||
ctx: Load,
|
||||
parenthesized: false,
|
||||
},
|
||||
),
|
||||
),
|
||||
name: None,
|
||||
body: [
|
||||
Pass(
|
||||
StmtPass {
|
||||
range: 75..79,
|
||||
},
|
||||
),
|
||||
],
|
||||
},
|
||||
),
|
||||
],
|
||||
orelse: [],
|
||||
finalbody: [],
|
||||
is_star: false,
|
||||
},
|
||||
),
|
||||
Try(
|
||||
StmtTry {
|
||||
range: 80..116,
|
||||
body: [
|
||||
Pass(
|
||||
StmtPass {
|
||||
range: 89..93,
|
||||
},
|
||||
),
|
||||
],
|
||||
handlers: [
|
||||
ExceptHandler(
|
||||
ExceptHandlerExceptHandler {
|
||||
range: 94..116,
|
||||
type_: Some(
|
||||
Tuple(
|
||||
ExprTuple {
|
||||
range: 102..106,
|
||||
elts: [
|
||||
Name(
|
||||
ExprName {
|
||||
range: 102..103,
|
||||
id: Name("x"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
Name(
|
||||
ExprName {
|
||||
range: 105..106,
|
||||
id: Name("y"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
],
|
||||
ctx: Load,
|
||||
parenthesized: false,
|
||||
},
|
||||
),
|
||||
),
|
||||
name: None,
|
||||
body: [
|
||||
Pass(
|
||||
StmtPass {
|
||||
range: 112..116,
|
||||
},
|
||||
),
|
||||
],
|
||||
},
|
||||
),
|
||||
],
|
||||
orelse: [],
|
||||
finalbody: [],
|
||||
is_star: true,
|
||||
},
|
||||
),
|
||||
],
|
||||
},
|
||||
)
|
||||
```
|
||||
## Unsupported Syntax Errors
|
||||
|
||||
|
|
||||
2 | try:
|
||||
3 | pass
|
||||
4 | except x, y:
|
||||
| ^^^^ Syntax Error: Multiple exception types must be parenthesized on Python 3.13 (syntax was added in Python 3.14)
|
||||
5 | pass
|
||||
6 | try:
|
||||
|
|
||||
|
||||
|
||||
|
|
||||
6 | try:
|
||||
7 | pass
|
||||
8 | except* x, y:
|
||||
| ^^^^ Syntax Error: Multiple exception types must be parenthesized on Python 3.13 (syntax was added in Python 3.14)
|
||||
9 | pass
|
||||
|
|
|
@ -0,0 +1,125 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/tests/fixtures.rs
|
||||
input_file: crates/ruff_python_parser/resources/inline/ok/except_stmt_unparenthesized_tuple_no_as_py314.py
|
||||
---
|
||||
## AST
|
||||
|
||||
```
|
||||
Module(
|
||||
ModModule {
|
||||
range: 0..117,
|
||||
body: [
|
||||
Try(
|
||||
StmtTry {
|
||||
range: 44..79,
|
||||
body: [
|
||||
Pass(
|
||||
StmtPass {
|
||||
range: 53..57,
|
||||
},
|
||||
),
|
||||
],
|
||||
handlers: [
|
||||
ExceptHandler(
|
||||
ExceptHandlerExceptHandler {
|
||||
range: 58..79,
|
||||
type_: Some(
|
||||
Tuple(
|
||||
ExprTuple {
|
||||
range: 65..69,
|
||||
elts: [
|
||||
Name(
|
||||
ExprName {
|
||||
range: 65..66,
|
||||
id: Name("x"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
Name(
|
||||
ExprName {
|
||||
range: 68..69,
|
||||
id: Name("y"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
],
|
||||
ctx: Load,
|
||||
parenthesized: false,
|
||||
},
|
||||
),
|
||||
),
|
||||
name: None,
|
||||
body: [
|
||||
Pass(
|
||||
StmtPass {
|
||||
range: 75..79,
|
||||
},
|
||||
),
|
||||
],
|
||||
},
|
||||
),
|
||||
],
|
||||
orelse: [],
|
||||
finalbody: [],
|
||||
is_star: false,
|
||||
},
|
||||
),
|
||||
Try(
|
||||
StmtTry {
|
||||
range: 80..116,
|
||||
body: [
|
||||
Pass(
|
||||
StmtPass {
|
||||
range: 89..93,
|
||||
},
|
||||
),
|
||||
],
|
||||
handlers: [
|
||||
ExceptHandler(
|
||||
ExceptHandlerExceptHandler {
|
||||
range: 94..116,
|
||||
type_: Some(
|
||||
Tuple(
|
||||
ExprTuple {
|
||||
range: 102..106,
|
||||
elts: [
|
||||
Name(
|
||||
ExprName {
|
||||
range: 102..103,
|
||||
id: Name("x"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
Name(
|
||||
ExprName {
|
||||
range: 105..106,
|
||||
id: Name("y"),
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
],
|
||||
ctx: Load,
|
||||
parenthesized: false,
|
||||
},
|
||||
),
|
||||
),
|
||||
name: None,
|
||||
body: [
|
||||
Pass(
|
||||
StmtPass {
|
||||
range: 112..116,
|
||||
},
|
||||
),
|
||||
],
|
||||
},
|
||||
),
|
||||
],
|
||||
orelse: [],
|
||||
finalbody: [],
|
||||
is_star: true,
|
||||
},
|
||||
),
|
||||
],
|
||||
},
|
||||
)
|
||||
```
|
Loading…
Add table
Add a link
Reference in a new issue