Add `get_model_state` to get validated doc.
Add get_model_state to Doc
This adds get_model_state which returns the entire doc state as the
pydantic model pass in as Model= during instantiation.
It's effectively the other side of apply_update.
If the doc has no Model defined it will raise a RuntimeError. If the doc is invalid it will raise a pydantic ValidationError.
Add to_py to Doc
get_mode_state uses a new to_py for Doc (1aa8dfca55ea8c08156ae3f867715df9c576397c)
It iterates through the roots of the Doc, converting them into their
native python types (using the underlying type's to_py() fn).
additional changes
Also, update apply_update to use model_validate instead of
Model(**value). This is more of a "style" thing.
See https://github.com/pydantic/pydantic/discussions/9676
Also add ruff to the test dependencies and format given it's config was already defined in pyproject.toml.
@davidbrochart This actually doesn't work in it's current iteration because _roots gets updated lazily when calling get(). Have you had any thoughts about how _roots maybe could be kept in sync? I think either making _roots look at the rust state directly, or updating _roots when running apply_update
Any thoughts?
Sorry @mnbbrown I'm a bit low on bandwidth currently, but excited to see what you're doing.
Sorry @mnbbrown I'm a bit low on bandwidth currently, but excited to see what you're doing.
No worries! I know how it is :)
I think this is ready for a review now - I hope the description is sufficiently clear. Let me know if anything else needs explanation.