mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-16 08:30:30 +00:00

## Summary Part of #17412 Add a new compile-time syntax error for detecting `nonlocal` declarations at a module level. ## Test Plan - Added new inline tests for the syntax error - Updated existing tests for `nonlocal` statement parsing to be inside a function scope Co-authored-by: Brent Westbrook <36778786+ntBre@users.noreply.github.com>
68 lines
2.2 KiB
Text
68 lines
2.2 KiB
Text
---
|
|
source: crates/ruff_python_parser/tests/fixtures.rs
|
|
input_file: crates/ruff_python_parser/resources/inline/ok/nonlocal_stmt.py
|
|
---
|
|
## AST
|
|
|
|
```
|
|
Module(
|
|
ModModule {
|
|
range: 0..45,
|
|
body: [
|
|
FunctionDef(
|
|
StmtFunctionDef {
|
|
range: 0..44,
|
|
is_async: false,
|
|
decorator_list: [],
|
|
name: Identifier {
|
|
id: Name("_"),
|
|
range: 4..5,
|
|
},
|
|
type_params: None,
|
|
parameters: Parameters {
|
|
range: 5..7,
|
|
posonlyargs: [],
|
|
args: [],
|
|
vararg: None,
|
|
kwonlyargs: [],
|
|
kwarg: None,
|
|
},
|
|
returns: None,
|
|
body: [
|
|
Nonlocal(
|
|
StmtNonlocal {
|
|
range: 13..23,
|
|
names: [
|
|
Identifier {
|
|
id: Name("x"),
|
|
range: 22..23,
|
|
},
|
|
],
|
|
},
|
|
),
|
|
Nonlocal(
|
|
StmtNonlocal {
|
|
range: 28..44,
|
|
names: [
|
|
Identifier {
|
|
id: Name("x"),
|
|
range: 37..38,
|
|
},
|
|
Identifier {
|
|
id: Name("y"),
|
|
range: 40..41,
|
|
},
|
|
Identifier {
|
|
id: Name("z"),
|
|
range: 43..44,
|
|
},
|
|
],
|
|
},
|
|
),
|
|
],
|
|
},
|
|
),
|
|
],
|
|
},
|
|
)
|
|
```
|