Skip to content

Keep exception message continuation lines as text - #13

Open
ump45nose wants to merge 1 commit into
ipython:mainfrom
ump45nose:fix/14142-traceback-message-backticks
Open

Keep exception message continuation lines as text#13
ump45nose wants to merge 1 commit into
ipython:mainfrom
ump45nose:fix/14142-traceback-message-backticks

Conversation

@ump45nose

Copy link
Copy Markdown

Fixes ipython/ipython#14142

Summary

IPythonPartialTracebackLexer ended its rules with a catch-all that
tagged every unmatched line as Other. IPythonTracebackLexer is a
DelegatingLexer, so Other tokens are re-lexed with the Python lexer.
Continuation lines of a multiline exception message are plain text, not
Python, so e.g. backticks in the message produced Error tokens that
broke highlighting (and sphinx/myst-nb builds using
RaiseOnErrorTokenFilter).

Numbered code-frame lines are matched by earlier rules whose code part
is still Other (and therefore still delegated to the Python lexer), so
this change only affects unmatched trailing text.

Changes

  • ipython_pygments_lexers.py: final fallback rule now emits Text
    instead of Other, with a comment explaining why.
  • test_ipython_pygments_lexers.py: regression test asserting no
    Error tokens for a multiline exception message containing backticks,
    including through RaiseOnErrorTokenFilter.

Tests

  • New test fails without the change and passes with it.
  • pytest → 8 passed.

The catch-all rule in IPythonPartialTracebackLexer tagged every
remaining line as Other.  IPythonTracebackLexer delegates Other tokens
to the Python lexer, so plain-text lines of a multiline exception
message were re-lexed as Python code, emitting Error tokens when the
message contained characters invalid in Python, such as backticks.

Emit Text instead: numbered code-frame lines are matched by earlier
rules and still delegate to the Python lexer.

Fixes ipython/ipython#14142.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IPythonTracebackLexer errors on back ticks in the presence of line-breaks

1 participant