Skip to content

Conversation

@reteps
Copy link

@reteps reteps commented Feb 10, 2026

Summary

  • Adds a relative_to parameter to Traceback, Traceback.from_exception(), install(), and Console.print_exception()
  • Shortens displayed file paths by stripping the given prefix, while preserving full paths for file existence checks and source code reading
  • Useful for projects with deep directory structures where absolute paths add noise

Test plan

  • test_relative_to: Verifies prefix is stripped from displayed paths
  • test_relative_to_source_renders: Verifies source code still renders correctly with shortened paths
  • All existing traceback tests pass
  • mypy strict mode passes
  • black formatting clean

🤖 Generated with Claude Code

Adds a `relative_to` parameter to `Traceback`, `Traceback.from_exception()`,
`install()`, and `Console.print_exception()` that shortens displayed file paths
by stripping a common prefix, while preserving full paths for file existence
checks and source code reading.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@reteps
Copy link
Author

reteps commented Feb 10, 2026

I did not see any policy for AI-assisted contributions, but please let me know if I should close this. This is a feature I monkey-patched for my own needs I thought might be useful to others, so I am upstreaming it. Thanks!

@reteps reteps marked this pull request as ready for review February 10, 2026 19:49
@reteps
Copy link
Author

reteps commented Feb 10, 2026

In my case, I have some highly nested paths that can hurt traceback visibility.

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.

1 participant