We’ve just released jupyter-client 5.1, including a definition of version
5.2 of the Jupyter protocol.

The main issue in protocol 5.2 is resolving ambiguity about the cursor_pos
field in inspection/completion messages in the presence of non-BMP (“astral
plane”) characters. The protocol has always defined cursor_pos in terms of
unicode *characters*, but due to widespread bugs in frontends (all known
javascript-based frontends and some Python frontends when running with
Python 2 on certain platforms) not handling surrogate pairs correctly,
cursor_pos has been ambiguous *in practice* until now. Given the prevalence
of the bug, Kernel authors *may* choose to interpret cursor_pos coming from
protocol version 5.1 or earlier as the UTF-16 code unit offset, rather than
the encoding-independent *code point* offset, because that would be the
correct behavior for the most widespread frontend (jupyter notebook). This
would not *technically* be a correct implementation of protocol v5.1, but
if your users mostly use the notebook it would match your frontend.

Kernel and frontend authors should check the length of a string containing
codepoints >= 0x10000, such as ‘𝐚’. If the length of such a
single-character is two, you will need to translate between string index
and unicode index for cursor_pos. Only once this has been addressed should
your kernel or frontend self-identify as implementing protocol version 5.2.

Notebook 5.1 (soon) and JupyterLab 0.24 (out) implement this correctly and
identify as protocol 5.2.

   - JupyterLab fix
   
<https://github.com/jupyterlab/jupyterlab/pull/2404/files#diff-0d02a0618e7a24c17bb9291b890414f8>
   - GitHub issue <https://github.com/jupyter/jupyter_client/pull/262>
   - note in docs
   
<https://jupyter-client.readthedocs.io/en/latest/messaging.html#cursor-pos-unicode-note>
   - jupyter-client release notes
   <https://jupyter-client.readthedocs.io/en/5.1.0/changelog.html#id1>

-Min
​

-- 
You received this message because you are subscribed to the Google Groups 
"Project Jupyter" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jupyter/CAHNn8BUwjLJNgzi_%3DaAxhMEUF4n9QzHXC1_Zwzeu0%3DP%2BtP1pqg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to