Skip to content

Commit c6e60a4

Browse files
chore: bump version to 0.4.0 and update docs (#30)
1 parent 9dcc3c7 commit c6e60a4

5 files changed

Lines changed: 26 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
# Changelog
22

3+
## 0.4.0
4+
5+
### Features
6+
7+
- Added `Document.insert()` and `Editor.insert()` for inserting an item at a specific position in a sequence. Uses Python `list.insert()` semantics (negative indices count from end, out-of-range clamps).
8+
- Added `Document.get()` and `Editor.get()` for non-raising value access. This returns a default (defaults to `None`) when the path doesn't exist, similar to `dict.get()`.
9+
- Added `Document.sync()` and `Editor.sync()` that diffs the current value at a path against a desired value and applies the minimal set of patches. Supports recursive mapping diffing and `SequenceMatcher`-based list diffing to preserve comments and formatting on unchanged elements.
10+
11+
### Internal
12+
13+
- Introduced `OpInner` enum in Rust to support local ops (like `insert_at`) alongside yamlpatch-delegated operations.
14+
- Extracted `KeyPart` type alias to `_types.py`.
15+
316
## 0.3.0
417

518
### Features

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "yamltrip"
3-
version = "0.3.0"
3+
version = "0.4.0"
44
edition = "2024"
55
license = "MIT"
66

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ doc["items"] # ["a", "b"]
6565
doc["items", 0] # "a"
6666
("items", 0) in doc # True
6767

68+
doc.get("items", 0) # "a" (returns None if missing)
69+
doc.get("missing", default=42) # 42
70+
6871
doc.replace("items", 0, value="x")
6972
doc.replace("items", value=["x", "y"]) # dicts and lists accepted
7073
doc.add("items", key="c", value=3)
@@ -73,8 +76,10 @@ doc.upsert("config", value={"debug": True}) # dicts and lists accepted
7376
doc.remove("items", 0)
7477
doc.prune_remove("a", "b", "c") # remove + prune empty parents
7578
doc.append("items", value="c")
79+
doc.insert("items", index=1, value="between") # positional insert
7680
doc.extend_list("items", values=["d", "e"])
7781
doc.remove_from_list("items", values=["a"])
82+
doc.sync("items", value=["a", "new", "b"]) # minimal diff-and-patch
7883

7984
doc.query("items") # Feature with location info
8085
doc.query_pretty("items") # Feature with surrounding context
@@ -94,7 +99,9 @@ with yamltrip.edit("config.yml") as ed:
9499
ed.replace("version", value="2.0")
95100
ed.upsert("new_key", value="new_value")
96101
ed.remove("old_key")
102+
ed.sync("deps", value={"a": "1.0", "b": "2.0"}) # minimal patching
97103
print(ed["version"]) # "2.0"
104+
print(ed.get("missing")) # None
98105
print(ed.original["version"]) # original value before edits
99106
```
100107

@@ -131,8 +138,9 @@ All yamltrip errors inherit from `YAMLTripError`:
131138
- **Integer keys cannot create structures.** `upsert()` with integer path
132139
components can update existing sequence entries but cannot create new
133140
intermediate mappings. Only string keys create new mappings.
134-
- **No negative sequence indices.** Python-style negative indexing is not
135-
supported.
141+
- **No negative sequence indices for lookup.** Python-style negative indexing
142+
is not supported for `[]` access or `replace()`/`remove()`. However,
143+
`insert()` accepts negative indices (matching `list.insert()` semantics).
136144
- **Line endings preserved as-is.** No CRLF/LF normalization. Mixed line
137145
endings pass through unchanged.
138146

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ requires = [ "maturin>=1.0,<2.0" ]
44

55
[project]
66
name = "yamltrip"
7-
version = "0.3.0"
7+
version = "0.4.0"
88
description = "A round-tripping YAML library for Python"
99
readme = "README.md"
1010
authors = [ { name = "Nathan McDougall", email = "nathan.j.mcdougall@gmail.com" } ]

0 commit comments

Comments
 (0)