You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, one must bind an empty shared type to Ydoc keys before accessing their values:
ydoc["cells"] =Array()
assertydoc["cells"].to_py() == [{"metadata": {"foo": "bar"}, "source": "1 + 2"}]
# ^- not equal to the empty Array() assigned to this key immediately before,# but rather the value coming from another provider
There are two drawbacks to only supporting this way of accessing a shared type:
This requires 1 additional line of code per shared type for the assignment statement, and can get verbose if one is using many. However, in Yjs, ydoc.getArray(...) can be used inline.
The inline assignment operator := (available in Python 3.8+) does not work either:
/Users/dlq/micromamba/envs/rtcdev/lib/python3.11/ast.py:50: in parse
return compile(source, filename, mode, flags,
E File "/Volumes/workplace/pycrdt-websocket/tests/test_pycrdt_yjs.py", line 92
E assert (ydoc["cells"] := Array()).to_py() == [{"metadata": {"foo": "bar"}, "source": "1 + 2"}]
E ^^^^^^^^^^^^^
E SyntaxError: cannot use assignment expressions with subscript
BTW you can write doc["my_array"] = my_array = Array() if you want a one-liner.
The syntax requires assigning an empty shared type in order to access an existing, non-empty shared type. This is stateful and confusing, because the value of ydoc["cells"] is not the value of ydoc["cells"] that was just set in the immediately preceding line. This generally violates how most programming languages work. I understand that this is permitted by Python, but the public API should not rely on exotic behavior exclusive to Python.
Thank you for opening your first issue in this project! Engagement like this is essential for open source projects! 🤗
If you haven't done so already, check out Jupyter's Code of Conduct. Also, please try to follow the issue template as it helps other other community members to contribute more effectively.
You can meet the other Jovyans by joining our Discourse forum. There is also an intro thread there where you can stop by and say Hi! 👋
Problem
Currently, one must bind an empty shared type to Ydoc keys before accessing their values:
There are two drawbacks to only supporting this way of accessing a shared type:
ydoc.getArray(...)
can be used inline.:=
(available in Python 3.8+) does not work either:ydoc["cells"]
is not the value ofydoc["cells"]
that was just set in the immediately preceding line. This generally violates how most programming languages work. I understand that this is permitted by Python, but the public API should not rely on exotic behavior exclusive to Python.Proposed Solution
TBD.
Additional context
The text was updated successfully, but these errors were encountered: