1. Georg Brandl
  2. pygments-main
  3. Issues
Issue #360 resolved

PythonTracebackLexer doesn't properly handle SyntaxErrors or top-level KeyboardInterrupts

Anonymous created an issue

PythonTracebackLexer assumes all tracebacks start with Traceback (most recent call last): and erroneously highlights tracebacks that don't have them:

{{{

: File "<stdin>", line 1 : ^ SyntaxError: invalid syntax

KeyboardInterrupt

}}}

Using TerminalFormatter, Pygments highlights both with underlined red text.

Also, just to be clear, I'm talking about Pygments failing on ''just'' the traceback text above, not including the prompt text. And the SyntaxError format isn't specific to the interactive interpreter, though that KeyboardInterrupt format probably is.

Reported by guest

Comments (6)

  1. Anonymous

    Also, it currently seems to insert newlines in tracebacks that have code ending with a plus sign:

    >>> 1+
      File "<stdin>", line 1
        1+
         
    ^
    SyntaxError: invalid syntax
    

    Compared to the original:

    >>> 1+
      File "<stdin>", line 1
        1+
         ^
    SyntaxError: invalid syntax
    

    I'm not sure if this would go away if it properly recognized the traceback.

  2. Log in to comment