feat: add find_index() for list-of-dicts lookup#36
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds a convenience lookup API to yamltrip’s Python layer for locating the first matching entry in a list-of-dicts at a given document path, exposed on both Document (immutable) and Editor (context-managed mutable wrapper).
Changes:
- Add
Document.find_index(*keys, where=...) -> int | Noneimplementing AND-match semantics and skipping non-dict list items. - Add
Editor.find_index(...)delegating toDocument.find_index(...). - Add new test coverage for
Document.find_indexand basicEditor.find_indexbehavior, plus a design/spec markdown.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/yamltrip/document.py | Implements Document.find_index() and its validation/error behavior. |
| src/yamltrip/editor.py | Adds Editor.find_index() delegating to the underlying Document. |
| tests/test_document.py | Adds comprehensive tests for Document.find_index() (matching, errors, nested paths, int path keys, etc.). |
| tests/test_editor.py | Adds tests for Editor.find_index() basic matching and empty-where validation. |
| doc/specs/2026-05-22-find-index-design.md | Adds a design/spec document describing the new API and intended semantics. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
4232b54 to
0c8bdd1
Compare
entry.get(k) == v incorrectly matched missing keys when where contained None values. Use 'k in entry and entry[k] == v' so absent keys never satisfy the constraint.
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.
Adds
Document.find_index()andEditor.find_index()methods that return the index of the first list item matching a set of key/value constraints.API
Behavior
wherekey/value pairs match (AND semantics)Noneif no item matchesQueryErrorif path doesn't existNodeTypeErrorif value at path is not a listValueErrorifwhereis emptyMotivation
YAML configs frequently use lists of dicts keyed by a distinguishing field (e.g. pre-commit repos by URL, CI steps by
uses). Finding an item currently requires manual iteration:find_indexmakes this a single call.