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.
Type of changes
Checklist
Description
Pull request for https://github.com/Textualize/rich/issues/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