Skip to content

Commit 4facd87

Browse files
Add root property to Document and Editor
Provides doc.root as a convenient alternative to doc[()]. Returns the entire document parsed as a Python object.
1 parent dcc70a3 commit 4facd87

3 files changed

Lines changed: 11 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ modified.
5656
```python
5757
doc = yamltrip.loads("items:\n - a\n - b")
5858

59+
doc.root # {"items": ["a", "b"]}
5960
doc["items"] # ["a", "b"]
6061
doc["items", 0] # "a"
6162
("items", 0) in doc # True

src/yamltrip/document.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ def source(self) -> str:
9393
"""The current YAML source text."""
9494
return self._source
9595

96+
@property
97+
def root(self) -> Any:
98+
"""The entire document parsed as a Python object."""
99+
return self[()]
100+
96101
def __eq__(self, other: object) -> bool:
97102
"""Compare documents by their source text."""
98103
if not isinstance(other, Document):

src/yamltrip/editor.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ def document(self) -> Document:
8383
raise RuntimeError(msg)
8484
return self._document
8585

86+
@property
87+
def root(self) -> Any:
88+
"""The entire document parsed as a Python object."""
89+
return self.document.root
90+
8691
def __getitem__(self, keys: object) -> Any:
8792
"""Retrieve the parsed value at the given path."""
8893
return self.document[keys]

0 commit comments

Comments
 (0)