feat: human-readable path formatting in NodeTypeError messages#40
Merged
nathanjmcdougall merged 4 commits intoMay 22, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves NodeTypeError usability by replacing raw Python tuple representations of key paths (e.g., ('repos', 0, 'steps')) with a human-readable path string (e.g., repos > 0 > steps) in error messages emitted from Document list operations.
Changes:
- Added
yamltrip._display.format_path()to format(str|int, ...)key tuples intoa > 0 > bpath strings (with<root>for()). - Updated
Document.remove_from_list,Document.ensure_in_list, andDocument.find_indexto useformat_path(keys)in theirNodeTypeErrormessages. - Added focused unit tests for
format_pathand for the updatedNodeTypeErrormessage formatting.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
src/yamltrip/_display.py |
Introduces format_path() helper for human-readable key-path formatting. |
src/yamltrip/document.py |
Switches NodeTypeError message interpolation to use format_path() at three call sites. |
tests/test_display.py |
Adds unit tests covering format_path() behavior (single key, multi-key, int index, root). |
tests/test_document.py |
Adds assertions that list-operation NodeTypeError messages use the new path formatting. |
doc/specs/2026-05-22-error-message-tuple-repr-design.md |
Documents the problem, chosen formatting, and scope/testing plan. |
.importlinter |
Updates import-linter configuration to account for the new internal _display module. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Replace raw tuple repr in
NodeTypeErrormessages with human-readable path strings.Before:
Value at ('repos', 0, 'steps') is not a listAfter:
Value at repos > 0 > steps is not a listChanges
src/yamltrip/_display.pymodule withformat_pathhelperdocument.py:remove_from_list,ensure_in_list,find_indexformat_pathand error message formattingCloses #37