2286 pep657 error code ranges in traceback #3389
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Type of changes
Checklist
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
Rich traceback before
Rich traceback with highlighing