-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add merge() method + basedpyright type checking #41
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
c354119
fix: prevent nested dict flattening in _create_at
nathanjmcdougall 4731b1d
refactor: add remove_extra flag to _compute_patches
nathanjmcdougall 6162157
feat: add Document.merge() method
nathanjmcdougall 52c3afb
test: add merge edge case tests
nathanjmcdougall 7d9b764
feat: add Editor.merge() delegate
nathanjmcdougall 4bcb436
docs: add deep merge design spec and implementation plan
nathanjmcdougall 61083af
refactor: address review feedback
nathanjmcdougall 0db10d5
Merge remote-tracking branch 'origin/main' into feature/deep-merge
nathanjmcdougall 6636601
fix: use doc in merge fallback, add equality guard, add error test
nathanjmcdougall 298725c
fix: raise NodeTypeError on scalar traversal, remove broken spec refe…
nathanjmcdougall 324ac99
fix: improve merge comment clarity and NodeTypeError message format
nathanjmcdougall 45612d0
refactor: address review - improve error path, remove dead flow-seq c…
nathanjmcdougall ec8b01e
feat: add basedpyright type checking
nathanjmcdougall cb44356
fix: update DiffMode docstring to reference compute_patches
nathanjmcdougall 255d201
Potential fix for pull request finding
nathanjmcdougall File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,5 +18,3 @@ exhaustive_ignores = | |
| _display | ||
| _types | ||
| ignore_imports = | ||
| yamltrip.document -> yamltrip | ||
| yamltrip.sync -> yamltrip | ||
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| # Design: Deep Merge (`merge()`) | ||
|
|
||
| **Date:** 2026-05-22 | ||
| **Status:** Approved | ||
|
|
||
| ## Summary | ||
|
|
||
| Add a `merge()` method that recursively merges a value into an existing | ||
| mapping without removing keys not present in the target. Lists replace | ||
| entirely (list identity is ambiguous); only mapping keys get additive | ||
| treatment. | ||
|
|
||
| ## Semantics | ||
|
|
||
| | Current type | Target type | Behavior | | ||
| |---|---|---| | ||
| | mapping | mapping | Recurse: update matching keys, add new keys, never remove existing keys | | ||
| | list | list | Replace the list entirely | | ||
| | scalar | mapping | Replace scalar with mapping (promote) | | ||
| | mapping | scalar | Replace mapping with scalar | | ||
| | any | any (equal) | No-op | | ||
| | missing | any | Create path + set value (delegate to `upsert()`) | | ||
|
nathanjmcdougall marked this conversation as resolved.
|
||
|
|
||
|
nathanjmcdougall marked this conversation as resolved.
|
||
| Full-depth recursion always. No configurable depth parameter. | ||
|
|
||
| ## Public API | ||
|
|
||
| ```python | ||
| # Document (immutable, returns new Document) | ||
| doc = doc.merge(*keys, value={"debug": False, "timeout": 30}) | ||
|
|
||
| # Editor (mutable context manager) | ||
| with edit("config.yaml") as ed: | ||
| ed.merge("settings", value={"debug": False, "timeout": 30}) | ||
| ``` | ||
|
|
||
| Signature: `merge(self, *keys: KeyPart, value: Any) -> Document` | ||
|
|
||
| Matches `sync()` signature exactly. | ||
|
|
||
| ## Error behavior | ||
|
|
||
| - `NodeTypeError` if path traverses through a scalar/list where a mapping | ||
| is expected | ||
| - `PatchError` on Rust-level failures (same fallback as `sync()`) | ||
| - No new error types | ||
|
nathanjmcdougall marked this conversation as resolved.
|
||
|
|
||
| ## Scope | ||
|
|
||
| - No new Rust code — reuses existing patch primitives | ||
| - No new error types | ||
| - `sync()` behavior unchanged | ||
| - Available on both `Document` and `Editor` | ||
|
|
||
| ## Examples | ||
|
|
||
| ```python | ||
| from yamltrip import loads | ||
|
|
||
| doc = loads(""" | ||
| settings: | ||
| debug: true | ||
| log_level: info | ||
| custom_setting: 42 | ||
| """) | ||
|
|
||
| # Merge ensures debug+timeout exist without removing log_level/custom_setting | ||
| doc = doc.merge("settings", value={"debug": False, "timeout": 30}) | ||
|
|
||
| # Result: | ||
| # settings: | ||
| # debug: false | ||
| # log_level: info | ||
| # custom_setting: 42 | ||
| # timeout: 30 | ||
| ``` | ||
|
|
||
| ```python | ||
| # Lists replace entirely | ||
| doc = loads(""" | ||
| plugins: | ||
| - eslint | ||
| - prettier | ||
| """) | ||
|
|
||
| doc = doc.merge("plugins", value=["stylelint"]) | ||
|
|
||
| # Result: | ||
| # plugins: | ||
| # - stylelint | ||
| ``` | ||
|
|
||
| ```python | ||
| # Nested merge | ||
| doc = loads(""" | ||
| database: | ||
| host: localhost | ||
| credentials: | ||
| user: admin | ||
| password: secret | ||
| """) | ||
|
|
||
| doc = doc.merge("database", value={"credentials": {"user": "deploy"}, "port": 5432}) | ||
|
|
||
| # Result: | ||
| # database: | ||
| # host: localhost | ||
| # credentials: | ||
| # user: deploy | ||
| # password: secret | ||
| # port: 5432 | ||
| ``` | ||
|
|
||
| ## Testing | ||
|
|
||
| - Mapping merge: keeps extra keys, updates matching, adds new | ||
| - Nested mapping merge: recurses correctly | ||
| - List replacement: lists in target replace entirely | ||
| - Scalar-to-mapping promotion: works | ||
| - Missing path creation: delegates to upsert | ||
| - No-op when values equal: returns same Document instance | ||
| - Flow sequence handling: same fallback as sync | ||
| - Editor delegation: verify Editor.merge works | ||
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.