Skip to content

fix(traceback): highlight win32 paths #3734

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

### Fixed

- Fixed highlighting of Windows paths in tracebacks. https://github.com/Textualize/rich/pull/3734

## [14.0.0] - 2025-03-30

### Added
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ The following people have contributed to the development of Rich:
- [Paul McGuire](https://github.com/ptmcg)
- [Antony Milne](https://github.com/AntonyMilneQB)
- [Michael Milton](https://github.com/multimeric)
- [Zoltan Nagy](https://github.com/abesto)
- [Martina Oefelein](https://github.com/oefe)
- [Nathan Page](https://github.com/nathanrpage97)
- [Dave Pearson](https://github.com/davep/)
Expand Down
2 changes: 1 addition & 1 deletion rich/traceback.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ class Trace:


class PathHighlighter(RegexHighlighter):
highlights = [r"(?P<dim>.*/)(?P<bold>.+)"]
highlights = [r"(?P<dim>.*(/|\\))(?P<bold>.+)"]


class Traceback:
Expand Down
18 changes: 17 additions & 1 deletion tests/test_traceback.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
import pytest

from rich.console import Console
from rich.text import Span
from rich.theme import Theme
from rich.traceback import Traceback, install
from rich.traceback import install, PathHighlighter, Traceback


def test_handler():
Expand Down Expand Up @@ -373,3 +374,18 @@ def test_notes() -> None:
traceback = Traceback()

assert traceback.trace.stacks[0].notes == ["Hello", "World"]


def test_path_highlighter() -> None:
"""Check that PathHighlighter correctly highlights both win32 and *nix paths"""
path_highlighter = PathHighlighter()

assert path_highlighter("/foo/bar/baz").spans == [
Span(0, 9, "dim"),
Span(9, 12, "bold"),
]

assert path_highlighter("'\\\\?\\C:\\foo\\bar\\baz").spans == [
Span(0, 16, "dim"),
Span(16, 19, "bold"),
]
Loading