Repository navigation
fix windows file links in RichHandler using Path.as_uri() - #4140
VectorSophie wants to merge 1 commit into
Conversation
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Hi, I tried to open a PR but GitHub says PRs are restricted to collaborators. |
UnderHear
left a comment
There was a problem hiding this comment.
AI-assisted source review by dot; I have not run the tests.
At c2250b5, the new test_link_path_uri_format has contradictory assertions on POSIX when the checkout path contains no characters requiring URI escaping. For example, if abs_path is /tmp/rich/tests/test_logging.py, both Path(abs_path).as_uri() and "file://" + abs_path are file:///tmp/rich/tests/test_logging.py. Line 147 requires that URI to occur in link_styles, while line 150 forbids the identical string, so the test rejects the correct POSIX result.
Could the negative assertion be restricted to the malformed Windows case, or replaced with exact assertions on the filename and line-number links against Path(abs_path).as_uri() and its #1 form? A Linux/macOS checkout with a plain path would exercise this contradiction.
agammann
left a comment
There was a problem hiding this comment.
[P2] Resolve relative log paths before calling as_uri()
In rich/_log_render.py, Path(link_path).as_uri() raises ValueError for a relative path. RichHandler.render() passes record.pathname through as link_path, and a LogRecord can have a relative pathname (for example, code compiled with a relative filename or a manually constructed record). Rendering happens before emit() enters its print error handler, so one such log call now raises instead of logging. Could this resolve the path to an absolute path before as_uri() (or retain a safe fallback), and cover a relative link_path in a test?
Fixes #4093