mirror of
https://github.com/astral-sh/ruff.git
synced 2025-11-02 21:03:11 +00:00
[ty] continue and break statements outside loops are syntax errors (#20944)
Co-authored-by: Brent Westbrook <brentrwestbrook@gmail.com>
This commit is contained in:
parent
c424007645
commit
c7e2bfd759
3 changed files with 130 additions and 1 deletions
|
|
@ -354,3 +354,25 @@ def f():
|
|||
x = 1
|
||||
global x # error: [invalid-syntax] "name `x` is used prior to global declaration"
|
||||
```
|
||||
|
||||
## `break` and `continue` outside a loop
|
||||
|
||||
<!-- snapshot-diagnostics -->
|
||||
|
||||
```py
|
||||
break # error: [invalid-syntax]
|
||||
continue # error: [invalid-syntax]
|
||||
|
||||
for x in range(42):
|
||||
break # fine
|
||||
continue # fine
|
||||
|
||||
def _():
|
||||
break # error: [invalid-syntax]
|
||||
continue # error: [invalid-syntax]
|
||||
|
||||
class Fine:
|
||||
# this is invalid syntax despite it being in an eager-nested scope!
|
||||
break # error: [invalid-syntax]
|
||||
continue # error: [invalid-syntax]
|
||||
```
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue