mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-16 01:25:22 +00:00
Include soft keywords for is_keyword
check (#11445)
## Summary This PR updates the `TokenKind::is_keyword` check to include soft keywords. To account for this change, it adds a new `is_non_soft_keyword` method. The usage in logical line rules were updated to use the `is_non_soft_keyword` method but it'll be updated to use `is_keyword` in a follow-up PR (#11446). While, the parser usages were kept as is. And because of that, the snapshots for two test cases were updated in a better direction. ## Test Plan `cargo insta test`
This commit is contained in:
parent
43e8147eaf
commit
83152fff92
7 changed files with 94 additions and 133 deletions
|
@ -11,7 +11,7 @@ Module(
|
|||
body: [
|
||||
AnnAssign(
|
||||
StmtAnnAssign {
|
||||
range: 0..2,
|
||||
range: 0..7,
|
||||
target: Name(
|
||||
ExprName {
|
||||
range: 0..1,
|
||||
|
@ -21,26 +21,27 @@ Module(
|
|||
),
|
||||
annotation: Name(
|
||||
ExprName {
|
||||
range: 2..2,
|
||||
id: "",
|
||||
ctx: Invalid,
|
||||
range: 3..7,
|
||||
id: "type",
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
value: None,
|
||||
simple: true,
|
||||
},
|
||||
),
|
||||
TypeAlias(
|
||||
StmtTypeAlias {
|
||||
range: 3..15,
|
||||
name: Name(
|
||||
ExprName {
|
||||
range: 8..9,
|
||||
id: "X",
|
||||
ctx: Store,
|
||||
},
|
||||
),
|
||||
type_params: None,
|
||||
Assign(
|
||||
StmtAssign {
|
||||
range: 8..15,
|
||||
targets: [
|
||||
Name(
|
||||
ExprName {
|
||||
range: 8..9,
|
||||
id: "X",
|
||||
ctx: Store,
|
||||
},
|
||||
),
|
||||
],
|
||||
value: Name(
|
||||
ExprName {
|
||||
range: 12..15,
|
||||
|
@ -52,33 +53,34 @@ Module(
|
|||
),
|
||||
Expr(
|
||||
StmtExpr {
|
||||
range: 16..23,
|
||||
range: 16..28,
|
||||
value: Lambda(
|
||||
ExprLambda {
|
||||
range: 16..23,
|
||||
range: 16..28,
|
||||
parameters: None,
|
||||
body: Name(
|
||||
ExprName {
|
||||
range: 23..23,
|
||||
id: "",
|
||||
ctx: Invalid,
|
||||
range: 24..28,
|
||||
id: "type",
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
TypeAlias(
|
||||
StmtTypeAlias {
|
||||
range: 24..36,
|
||||
name: Name(
|
||||
ExprName {
|
||||
range: 29..30,
|
||||
id: "X",
|
||||
ctx: Store,
|
||||
},
|
||||
),
|
||||
type_params: None,
|
||||
Assign(
|
||||
StmtAssign {
|
||||
range: 29..36,
|
||||
targets: [
|
||||
Name(
|
||||
ExprName {
|
||||
range: 29..30,
|
||||
id: "X",
|
||||
ctx: Store,
|
||||
},
|
||||
),
|
||||
],
|
||||
value: Name(
|
||||
ExprName {
|
||||
range: 33..36,
|
||||
|
@ -96,7 +98,14 @@ Module(
|
|||
|
||||
|
|
||||
1 | a: type X = int
|
||||
| ^^^^ Syntax Error: Expected an expression
|
||||
| ^^^^ Syntax Error: Expected an identifier, but found a keyword 'type' that cannot be used here
|
||||
2 | lambda: type X = int
|
||||
|
|
||||
|
||||
|
||||
|
|
||||
1 | a: type X = int
|
||||
| ^ Syntax Error: Simple statements must be separated by newlines or semicolons
|
||||
2 | lambda: type X = int
|
||||
|
|
||||
|
||||
|
@ -104,5 +113,12 @@ Module(
|
|||
|
|
||||
1 | a: type X = int
|
||||
2 | lambda: type X = int
|
||||
| ^^^^ Syntax Error: Expected an expression
|
||||
| ^^^^ Syntax Error: Expected an identifier, but found a keyword 'type' that cannot be used here
|
||||
|
|
||||
|
||||
|
||||
|
|
||||
1 | a: type X = int
|
||||
2 | lambda: type X = int
|
||||
| ^ Syntax Error: Simple statements must be separated by newlines or semicolons
|
||||
|
|
||||
|
|
|
@ -12,38 +12,11 @@ Module(
|
|||
Expr(
|
||||
StmtExpr {
|
||||
range: 0..7,
|
||||
value: Generator(
|
||||
ExprGenerator {
|
||||
range: 0..7,
|
||||
elt: Name(
|
||||
ExprName {
|
||||
range: 1..1,
|
||||
id: "",
|
||||
ctx: Invalid,
|
||||
},
|
||||
),
|
||||
generators: [
|
||||
Comprehension {
|
||||
range: 1..6,
|
||||
target: Name(
|
||||
ExprName {
|
||||
range: 6..6,
|
||||
id: "",
|
||||
ctx: Store,
|
||||
},
|
||||
),
|
||||
iter: Name(
|
||||
ExprName {
|
||||
range: 6..6,
|
||||
id: "",
|
||||
ctx: Invalid,
|
||||
},
|
||||
),
|
||||
ifs: [],
|
||||
is_async: true,
|
||||
},
|
||||
],
|
||||
parenthesized: true,
|
||||
value: Name(
|
||||
ExprName {
|
||||
range: 1..6,
|
||||
id: "async",
|
||||
ctx: Load,
|
||||
},
|
||||
),
|
||||
},
|
||||
|
@ -95,14 +68,7 @@ Module(
|
|||
|
||||
|
|
||||
1 | (async)
|
||||
| ^^^^^ Syntax Error: Expected an expression
|
||||
2 | (x async x in iter)
|
||||
|
|
||||
|
||||
|
||||
|
|
||||
1 | (async)
|
||||
| ^ Syntax Error: Expected 'for', found ')'
|
||||
| ^^^^^ Syntax Error: Expected an identifier, but found a keyword 'async' that cannot be used here
|
||||
2 | (x async x in iter)
|
||||
|
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue