[syntax-errors] nonlocal declaration at module level (#17559)

## 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>
This commit is contained in:
Abhijeet Prasad Bodas 2025-04-25 01:41:46 +05:30 committed by GitHub
parent 538393d1f3
commit cf59cee928
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 363 additions and 131 deletions

View file

@ -0,0 +1,2 @@
nonlocal x
nonlocal x, y

View file

@ -1 +1,2 @@
nonlocal
def _():
nonlocal

View file

@ -1 +1,2 @@
nonlocal x + 1
def _():
nonlocal x + 1

View file

@ -1,3 +1,4 @@
nonlocal ,
nonlocal x,
nonlocal x, y,
def _():
nonlocal ,
nonlocal x,
nonlocal x, y,

View file

@ -0,0 +1,2 @@
def _():
nonlocal x

View file

@ -1,2 +1,3 @@
nonlocal x
nonlocal x, y, z
def _():
nonlocal x
nonlocal x, y, z