-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[syntax-errors] Improve error message and range for pre-PEP-614 decorator syntax errors #16581
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| # parse_options: { "target-version": "3.8" } | ||
| async def foo(): | ||
| @await bar | ||
| def baz(): ... |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # parse_options: { "target-version": "3.8" } | ||
| @{3: 3} | ||
| def bar(): ... |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # parse_options: { "target-version": "3.8" } | ||
| @3.14 | ||
| def bar(): ... |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| # parse_options: { "target-version": "3.9" } | ||
| async def foo(): | ||
| @await bar | ||
| def baz(): ... |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| --- | ||
| source: crates/ruff_python_parser/tests/fixtures.rs | ||
| input_file: crates/ruff_python_parser/resources/inline/err/decorator_await_expression_py38.py | ||
| --- | ||
| ## AST | ||
|
|
||
| ``` | ||
| Module( | ||
| ModModule { | ||
| range: 0..96, | ||
| body: [ | ||
| FunctionDef( | ||
| StmtFunctionDef { | ||
| range: 45..95, | ||
| is_async: true, | ||
| decorator_list: [], | ||
| name: Identifier { | ||
| id: Name("foo"), | ||
| range: 55..58, | ||
| }, | ||
| type_params: None, | ||
| parameters: Parameters { | ||
| range: 58..60, | ||
| posonlyargs: [], | ||
| args: [], | ||
| vararg: None, | ||
| kwonlyargs: [], | ||
| kwarg: None, | ||
| }, | ||
| returns: None, | ||
| body: [ | ||
| FunctionDef( | ||
| StmtFunctionDef { | ||
| range: 66..95, | ||
| is_async: false, | ||
| decorator_list: [ | ||
| Decorator { | ||
| range: 66..76, | ||
| expression: Await( | ||
| ExprAwait { | ||
| range: 67..76, | ||
| value: Name( | ||
| ExprName { | ||
| range: 73..76, | ||
| id: Name("bar"), | ||
| ctx: Load, | ||
| }, | ||
| ), | ||
| }, | ||
| ), | ||
| }, | ||
| ], | ||
| name: Identifier { | ||
| id: Name("baz"), | ||
| range: 85..88, | ||
| }, | ||
| type_params: None, | ||
| parameters: Parameters { | ||
| range: 88..90, | ||
| posonlyargs: [], | ||
| args: [], | ||
| vararg: None, | ||
| kwonlyargs: [], | ||
| kwarg: None, | ||
| }, | ||
| returns: None, | ||
| body: [ | ||
| Expr( | ||
| StmtExpr { | ||
| range: 92..95, | ||
| value: EllipsisLiteral( | ||
| ExprEllipsisLiteral { | ||
| range: 92..95, | ||
| }, | ||
| ), | ||
| }, | ||
| ), | ||
| ], | ||
| }, | ||
| ), | ||
| ], | ||
| }, | ||
| ), | ||
| ], | ||
| }, | ||
| ) | ||
| ``` | ||
| ## Unsupported Syntax Errors | ||
|
|
||
| | | ||
| 1 | # parse_options: { "target-version": "3.8" } | ||
| 2 | async def foo(): | ||
| 3 | @await bar | ||
| | ^^^^^^^^^ Syntax Error: Cannot use `await` expression outside function-call arguments in a decorator on Python 3.8 (syntax was added in Python 3.9) | ||
|
||
| 4 | def baz(): ... | ||
| | | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| --- | ||
| source: crates/ruff_python_parser/tests/fixtures.rs | ||
| input_file: crates/ruff_python_parser/resources/inline/err/decorator_dict_literal_py38.py | ||
| --- | ||
| ## AST | ||
|
|
||
| ``` | ||
| Module( | ||
| ModModule { | ||
| range: 0..68, | ||
| body: [ | ||
| FunctionDef( | ||
| StmtFunctionDef { | ||
| range: 45..67, | ||
| is_async: false, | ||
| decorator_list: [ | ||
| Decorator { | ||
| range: 45..52, | ||
| expression: Dict( | ||
| ExprDict { | ||
| range: 46..52, | ||
| items: [ | ||
| DictItem { | ||
| key: Some( | ||
| NumberLiteral( | ||
| ExprNumberLiteral { | ||
| range: 47..48, | ||
| value: Int( | ||
| 3, | ||
| ), | ||
| }, | ||
| ), | ||
| ), | ||
| value: NumberLiteral( | ||
| ExprNumberLiteral { | ||
| range: 50..51, | ||
| value: Int( | ||
| 3, | ||
| ), | ||
| }, | ||
| ), | ||
| }, | ||
| ], | ||
| }, | ||
| ), | ||
| }, | ||
| ], | ||
| name: Identifier { | ||
| id: Name("bar"), | ||
| range: 57..60, | ||
| }, | ||
| type_params: None, | ||
| parameters: Parameters { | ||
| range: 60..62, | ||
| posonlyargs: [], | ||
| args: [], | ||
| vararg: None, | ||
| kwonlyargs: [], | ||
| kwarg: None, | ||
| }, | ||
| returns: None, | ||
| body: [ | ||
| Expr( | ||
| StmtExpr { | ||
| range: 64..67, | ||
| value: EllipsisLiteral( | ||
| ExprEllipsisLiteral { | ||
| range: 64..67, | ||
| }, | ||
| ), | ||
| }, | ||
| ), | ||
| ], | ||
| }, | ||
| ), | ||
| ], | ||
| }, | ||
| ) | ||
| ``` | ||
| ## Unsupported Syntax Errors | ||
|
|
||
| | | ||
| 1 | # parse_options: { "target-version": "3.8" } | ||
| 2 | @{3: 3} | ||
| | ^^^^^^ Syntax Error: Cannot use a dict literal outside function-call arguments in a decorator on Python 3.8 (syntax was added in Python 3.9) | ||
| 3 | def bar(): ... | ||
| | |
Uh oh!
There was an error while loading. Please reload this page.