From 429008e86322cdb0990bec8628f19b009dbd8ff9 2014-08-13 18:02:42 From: Thomas Kluyver Date: 2014-08-13 18:02:42 Subject: [PATCH] Catch SyntaxError from tokenizing for traceback I don't think there's an easy way to test this, but I've verified the fix by hand. Closes gh-6300 --- diff --git a/IPython/core/ultratb.py b/IPython/core/ultratb.py index 8d02e8a..5fa0113 100644 --- a/IPython/core/ultratb.py +++ b/IPython/core/ultratb.py @@ -805,8 +805,10 @@ class VerboseTB(TBTools): elif token_type == tokenize.NEWLINE: break - except (IndexError, UnicodeDecodeError): + except (IndexError, UnicodeDecodeError, SyntaxError): # signals exit of tokenizer + # SyntaxError can occur if the file is not actually Python + # - see gh-6300 pass except tokenize.TokenError as msg: _m = ("An unexpected error occurred while tokenizing input\n"