(Translated by https://www.hiragana.jp/)
2286 pep657 error code ranges in traceback by Gothingbop · Pull Request #3389 · Textualize/rich · GitHub
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

2286 pep657 error code ranges in traceback #3389

Conversation

Gothingbop
Copy link

Type of changes

  • Bug fix
  • New feature
  • Documentation / docstrings
  • Tests
  • Other

Checklist

  • I've run the latest black with default args on new code.
  • I've updated CHANGELOG.md and CONTRIBUTORS.md where appropriate.
  • I've added tests for new code.
  • I accept that @willmcgugan may be pedantic in the code review.

Description

Pull request for #2286

Replicates some of the functionality in PEP 657 by extracting the col range of the exception and adds the style to the Syntax using Syntax.stylize_range().

Effectively repurposes code found in some private functions in the base traceback module: _get_code_position() and _walk_tb_with_full_positions(). The code would be cleaner if those functions were not private or we were OK with using private functions (raises an error when running the mypy type checking).

I can also abstract the loop into a generator to more closely replicate the _walk_tb_with_full_positions() functionality, but I'm unsure where the best spot for that would be.

Base Python traceback

image

Rich traceback before

image

Rich traceback with highlighing

image

@willmcgugan
Copy link
Collaborator

Great in principle.

I think we can improve on the styles a bit. And some of the information present in the ascii version doesn't seem to be styled.

This will also need to handle older Pythons.

@willmcgugan
Copy link
Collaborator

Thanks. Closed in favor of #3486

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.

2 participants