Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ modified.
```python
doc = yamltrip.loads("items:\n - a\n - b")

doc.root # {"items": ["a", "b"]}
doc["items"] # ["a", "b"]
doc["items", 0] # "a"
("items", 0) in doc # True
Expand Down
5 changes: 5 additions & 0 deletions src/yamltrip/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ def source(self) -> str:
"""The current YAML source text."""
return self._source

@property
def root(self) -> Any:
"""The entire document parsed as a Python object."""
return self[()]

def __eq__(self, other: object) -> bool:
"""Compare documents by their source text."""
if not isinstance(other, Document):
Expand Down
5 changes: 5 additions & 0 deletions src/yamltrip/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ def document(self) -> Document:
raise RuntimeError(msg)
return self._document

@property
def root(self) -> Any:
"""The entire document parsed as a Python object."""
return self.document.root

def __getitem__(self, keys: object) -> Any:
"""Retrieve the parsed value at the given path."""
return self.document[keys]
Expand Down
Loading