Message414518
Many thanks Pablo for the clear explanation. I'd prefer that the issue remain open, as there's an important user experience issue here. I suspect there are other similar examples of how the compiler error messages could be improved.
Here's a change that doesn't seem to be too hard, that could fix the problem at hand.
The IndentationError occurred at a known location in the input string. So as part of error reporting truncate the input string and try to compile that. In other words, make a good faith attempt to find an earlier error.
I've attached a funny_break_error_fix.py which is a first draft implementation of this idea.
Here's the output:
===
$ python3 funny_break_error_fix.py funny_break_error.py
unexpected indent (funny_break_error.py, line 6)
Traceback (most recent call last):
File "funny_break_error_fix.py", line 3, in compile_fix
compile(source, filename, 'exec')
File "funny_break_error.py", line 6
else:
^
IndentationError: unexpected indent
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "funny_break_error_fix.py", line 18, in <module>
compile_fix(src.read(), filename, 'exec')
File "funny_break_error_fix.py", line 9, in compile_fix
compile(new_source, filename, 'exec')
File "funny_break_error.py", line 5
break
^
SyntaxError: 'break' outside loop
===
And in this case we've got hold of the first error (at the cost of compiling part of the source file twice). Many thanks again for the clear explanation, which I found most helpful when formulating the above fix. |
|
Date |
User |
Action |
Args |
2022-03-04 11:45:18 | jfine2358 | set | recipients:
+ jfine2358, lys.nikolaou, pablogsal |
2022-03-04 11:45:18 | jfine2358 | set | messageid: <1646394318.28.0.583958425503.issue46910@roundup.psfhosted.org> |
2022-03-04 11:45:18 | jfine2358 | link | issue46910 messages |
2022-03-04 11:45:18 | jfine2358 | create | |
|