Skip to content

Commit

Permalink
Update to Yrs 0.17.2 (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbrochart authored Dec 8, 2023
1 parent a595a9c commit fa3416d
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 17 deletions.
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ name = "pycrdt"
crate-type = ["cdylib"]

[dependencies]
lib0 = "0.16.10"
yrs = "0.16.10"
yrs = "0.17.2"

[dependencies.pyo3]
version = "0.19.2"
4 changes: 3 additions & 1 deletion python/pycrdt/doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ def _roots(self) -> dict[str, BaseType]:
with self.transaction() as txn:
assert txn._txn is not None
return {
key: cast(Type[BaseType], base_types[type(val)])(
key: None
if val is None
else cast(Type[BaseType], base_types[type(val)])(
_integrated=val, _doc=self
)
for key, val in self._doc.roots(txn._txn).items()
Expand Down
2 changes: 1 addition & 1 deletion src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use pyo3::prelude::*;
use pyo3::exceptions::{PyValueError, PyTypeError};
use pyo3::types::{PyList, PyString};
use yrs::{
Any,
ArrayRef,
Array as _Array,
Doc as _Doc,
Expand All @@ -13,7 +14,6 @@ use yrs::types::ToJson;
use yrs::types::text::TextPrelim;
use yrs::types::array::{ArrayPrelim, ArrayEvent as _ArrayEvent};
use yrs::types::map::MapPrelim;
use lib0::any::Any;
use crate::transaction::Transaction;
use crate::type_conversions::{events_into_py, py_to_any, ToPython};
use crate::text::Text;
Expand Down
2 changes: 1 addition & 1 deletion src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use pyo3::prelude::*;
use pyo3::exceptions::{PyValueError, PyTypeError};
use pyo3::types::{PyString, PyDict, PyList};
use yrs::{
Any,
Doc as _Doc,
MapRef,
Map as _Map,
Expand All @@ -13,7 +14,6 @@ use yrs::types::ToJson;
use yrs::types::text::TextPrelim;
use yrs::types::array::ArrayPrelim;
use yrs::types::map::{MapPrelim, MapEvent as _MapEvent};
use lib0::any::Any;
use crate::transaction::Transaction;
use crate::type_conversions::{EntryChangeWrapper, events_into_py, py_to_any, ToPython};
use crate::text::Text;
Expand Down
7 changes: 3 additions & 4 deletions src/type_conversions.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use lib0::any::Any;
use pyo3::prelude::*;
use pyo3::types::{IntoPyDict, PyAny, PyBool, PyByteArray, PyDict, PyFloat, PyList, PyLong, PyString};
use yrs::types::{Attrs, Change, EntryChange, Delta, Events, Path, PathSegment, Value};
use yrs::TransactionMut;
use yrs::{Any, TransactionMut};
use std::ops::Deref;
use std::collections::{VecDeque, HashMap};
use crate::text::{Text, TextEvent};
Expand Down Expand Up @@ -221,7 +220,7 @@ pub fn py_to_any(value: &PyAny) -> Any {
let a = py_to_any(i);
items.push(a);
}
Any::Array(Box::from(items))
Any::Array(items.into())
} else if value.is_instance_of::<PyDict>() {
let val = value.downcast::<PyDict>().unwrap();
let mut items: HashMap<String, Any> = HashMap::new();
Expand All @@ -230,7 +229,7 @@ pub fn py_to_any(value: &PyAny) -> Any {
let v = py_to_any(v);
items.insert(k, v);
}
Any::Map(Box::from(items))
Any::Map(items.into())
} else {
Any::Undefined
}
Expand Down
16 changes: 8 additions & 8 deletions tests/test_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,13 @@ def test_roots():
assert list(roots["b"]) == [5, 2, 8]
assert dict(roots["c"]) == {"k1": 1, "k2": 2}

# need to update to yrs v0.17.2
# see https://github.com/y-crdt/y-crdt/issues/364#issuecomment-1839791409

# local_doc = Doc()
# update = remote_doc.get_update()
# local_doc.apply_update(update)
# roots = dict(local_doc)
local_doc = Doc()
update = remote_doc.get_update()
local_doc.apply_update(update)
roots = dict(local_doc)
assert roots["a"] is None
assert roots["b"] is None
assert roots["c"] is None
# assert str(roots["a"]) == "foo"
# assert list(roots["b"]) == [5, 2, 8]
# assert dict(roots["c"]) == {"k1": 1, "k2": 2}
# assert dict(roots["c"]) == None # {"k1": 1, "k2": 2}

0 comments on commit fa3416d

Please sign in to comment.