[New-bugs-announce] [issue46910] Expect IndentationError, get SyntaxError: 'break' outside loop

Jonathan Fine report at bugs.python.org
Thu Mar 3 06:22:08 EST 2022


New submission from Jonathan Fine <jfine2358 at gmail.com>:

This arises from a request for help made by Nguyễn Ngọc Tiến to the visually impaired programmers lists, see https://www.freelists.org/post/program-l/python,48. Please keep this in mind.

Nguyễn asked for help with the syntax error created by
===
count = 0
while count < 1:
 count = count + 1
 print(count)
break
 else:
 print("no break")
===

When I saved this to a file and ran it I got:
===
$ python3.8 funny_break_error.py 
  File "funny_break_error.py", line 6
    else:
    ^
IndentationError: unexpected indent
===

However, remove the last two lines and you get the more helpful error
===
$ python3.8 funny_break_error.py 
  File "funny_break_error.py", line 5
    break
    ^
SyntaxError: 'break' outside loop
===

Python3.6 and 3.7 also behave as above.

Note. I've heard that blind Python programmers prefer a single space to denote indent. I think this is because they hear the leading spaces via a screen reader, rather than see the indent with their eyes.

----------
components: Parser
files: funny_break_error.py
messages: 414424
nosy: jfine2358, lys.nikolaou, pablogsal
priority: normal
severity: normal
status: open
title: Expect IndentationError, get SyntaxError: 'break' outside loop
type: behavior
versions: Python 3.7, Python 3.8
Added file: https://bugs.python.org/file50655/funny_break_error.py

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue46910>
_______________________________________


More information about the New-bugs-announce mailing list