Issue 16504: IDLE - fatal error when opening a file with certain tokenizing errors (original) (raw)

Created on 2012-11-18 17:37 by roger.serwy, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
editor_token_error.patch roger.serwy,2012-11-18 17:37 review
sample_token_error.py roger.serwy,2012-11-18 17:39
editor_token_error_rev1.patch roger.serwy,2012-11-18 19:06 review
Messages (9)
msg175895 - (view) Author: Roger Serwy (roger.serwy) * (Python committer) Date: 2012-11-18 17:37
IDLE's IndentSearcher class in EditorWindow.py can raise an uncaught IndentationError when opening a file. The attached patch fixes the problem by catching everything that the tokenize module can raise explicitly, namely IndentationError, TokenError, and SyntaxError. Alternatively, the except clause can be left bare, as it is disappointing to crash IDLE when simply guessing the indent width of a file. (See "guess_indent" in EditorWindow.py)
msg175896 - (view) Author: Roger Serwy (roger.serwy) * (Python committer) Date: 2012-11-18 17:39
I encountered this behavior while testing an extension that highlights tabs and trailing whitespace. The very first test file I wrote caused this crash. See the attached "sample_token_error.py".
msg175901 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-11-18 18:38
IndentationError is a subclass of SyntaxError.
msg175904 - (view) Author: Roger Serwy (roger.serwy) * (Python committer) Date: 2012-11-18 19:06
That's a good point. Attached is a revision to omit IndentationError. Thanks Serhiy.
msg176266 - (view) Author: Roger Serwy (roger.serwy) * (Python committer) Date: 2012-11-24 03:08
Serhiy, was meant for ?
msg176268 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-11-24 08:11
> Serhiy, was meant for ? Yes, sorry.
msg176890 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-12-04 10:17
LGTM.
msg178313 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012-12-27 20:05
New changeset d3c81ef728ae by Serhiy Storchaka in branch '2.7': Issue #16504: Catch SyntaxErrors raised by tokenizer in IDLE. http://hg.python.org/cpython/rev/d3c81ef728ae New changeset e1ef04cfb57c by Serhiy Storchaka in branch '3.2': Issue #16504: Catch SyntaxErrors raised by tokenizer in IDLE. http://hg.python.org/cpython/rev/e1ef04cfb57c New changeset f111e7078d54 by Serhiy Storchaka in branch '3.3': Issue #16504: Catch SyntaxErrors raised by tokenizer in IDLE. http://hg.python.org/cpython/rev/f111e7078d54 New changeset 69a2f6a7c257 by Serhiy Storchaka in branch 'default': Issue #16504: Catch SyntaxErrors raised by tokenizer in IDLE. http://hg.python.org/cpython/rev/69a2f6a7c257
msg178316 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-12-27 20:11
Thank you, Roger. Fixed.
History
Date User Action Args
2022-04-11 14:57:38 admin set github: 60708
2012-12-27 20:11:01 serhiy.storchaka set status: open -> closedresolution: fixedmessages: + stage: commit review -> resolved
2012-12-27 20:05:11 python-dev set nosy: + python-devmessages: +
2012-12-27 19:16:57 serhiy.storchaka set assignee: serhiy.storchaka
2012-12-04 10:17:20 serhiy.storchaka set nosy: + kbkmessages: + stage: commit review
2012-11-24 08:12:04 serhiy.storchaka set messages: -
2012-11-24 08:11:39 serhiy.storchaka set messages: +
2012-11-24 03:08:45 roger.serwy set messages: +
2012-11-23 21:37:04 serhiy.storchaka set messages: +
2012-11-23 20:09:53 terry.reedy set nosy: + terry.reedyversions: - Python 3.1
2012-11-18 19:06:11 roger.serwy set files: + editor_token_error_rev1.patchmessages: +
2012-11-18 18:38:22 serhiy.storchaka set nosy: + serhiy.storchakamessages: +
2012-11-18 17:39:54 roger.serwy set files: + sample_token_error.pymessages: +
2012-11-18 17:37:09 roger.serwy create