Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python console: do not require output that looks like a traceback to be valid #2410

Merged
merged 1 commit into from
Apr 12, 2023

Conversation

birkenfeld
Copy link
Member

which causes Error to be flagged with output that just happens to look like a traceback

Fixes #2407

@birkenfeld
Copy link
Member Author

Note: alternate fix would be to just allow stray lines in PythonTracebackLexer.

Copy link
Contributor

@jeanas jeanas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

As you submitted this I was preparing a change that actually highlights these tracebacks “correctly” (e.g., Generic.Traceback for all "Traceback (...):" lines), but being robust is always good.

@Anteru
Copy link
Collaborator

Anteru commented Apr 12, 2023

The fix is fine, but it produces "one character tokens". Can we track if we're in "error mode" and while we're in error mode, accumulate tokens, and if we're in the first non-error token, yield the whole text accumulated so far? We can also fix this in a subsequent release if this is too much work for now and we want the fix out.

@jeanas
Copy link
Contributor

jeanas commented Apr 12, 2023

Hmm, seems like the alternate fix would be better then?

If I understand correctly, it means

diff --git a/pygments/lexers/python.py b/pygments/lexers/python.py
index 6c89e6b5..eaaf6476 100644
--- a/pygments/lexers/python.py
+++ b/pygments/lexers/python.py
@@ -763,7 +763,8 @@ class PythonTracebackLexer(RegexLexer):
             (r'^([^:]+)(: )(.+)(\n)',
              bygroups(Generic.Error, Text, Name, Whitespace), '#pop'),
             (r'^([a-zA-Z_][\w.]*)(:?\n)',
-             bygroups(Generic.Error, Whitespace), '#pop')
+             bygroups(Generic.Error, Whitespace), '#pop'),
+            default('#pop'),
         ],
         'markers': [
             # Either `PEP 657 <https://www.python.org/dev/peps/pep-0657/>`

Right?

@birkenfeld
Copy link
Member Author

Yeah, true, I like this better then.

which causes Error to be flagged with console outputs that just happen
to look like a traceback

Fixes #2407
@birkenfeld birkenfeld merged commit 50dd4d8 into master Apr 12, 2023
@birkenfeld birkenfeld deleted the fix-2407 branch April 12, 2023 18:10
@Anteru Anteru added this to the 2.16.0 milestone Apr 12, 2023
@Anteru Anteru added the A-lexing area: changes to individual lexers label Apr 12, 2023
@Anteru Anteru modified the milestones: 2.16.0, 2.15.1 Apr 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lexing area: changes to individual lexers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Traceback parsing changes in 2.15.0 error on valid pycon code blocks
3 participants