Problem
Currently, accessing doc.root on a document with no YAML value (empty string, comment-only, or --- only) raises QueryError:
`python
import yamltrip
doc = yamltrip.loads('')
doc.root # raises QueryError: 'Path not found'
doc = yamltrip.loads('# just a comment\n')
doc.root # raises QueryError: 'Path not found'
doc = yamltrip.loads('---\n')
doc.root # raises QueryError: 'Path not found'
`
This forces every caller to wrap doc.root in a try/except, even though an empty document is a normal, expected state (e.g. a freshly created config file).
Proposal
Return None when the document has no root value node, consistent with how yamltrip.loads('null\n').root already returns None:
python @property def root(self) -> Any: try: return self[()] except QueryError: return None
Notes
- () in doc already returns False for empty docs, so the semantics are consistent.
- This is a Python-only change — no Rust modifications needed.
Problem
Currently, accessing doc.root on a document with no YAML value (empty string, comment-only, or --- only) raises QueryError:
`python
import yamltrip
doc = yamltrip.loads('')
doc.root # raises QueryError: 'Path not found'
doc = yamltrip.loads('# just a comment\n')
doc.root # raises QueryError: 'Path not found'
doc = yamltrip.loads('---\n')
doc.root # raises QueryError: 'Path not found'
`
This forces every caller to wrap doc.root in a try/except, even though an empty document is a normal, expected state (e.g. a freshly created config file).
Proposal
Return None when the document has no root value node, consistent with how yamltrip.loads('null\n').root already returns None:
python @property def root(self) -> Any: try: return self[()] except QueryError: return NoneNotes