Skip to content

Support cell.source as [list, of, strings] #111

@Wh1isper

Description

@Wh1isper

Description

https://nbformat.readthedocs.io/en/latest/format_description.html#cell-types

There are a few basic cell types for encapsulating code and text. All cells have the following basic structure:

{
"cell_type" : "type",
"metadata" : {},
"source" : "single string or [list, of, strings]",
}

In Jupyterlab3.x, cell.source is [list, of, strings], which causes

  File "/opt/conda/lib/python3.9/site-packages/jupyter_ydoc/ydoc.py", line 30, in source
    return self.set(value)
  File "/opt/conda/lib/python3.9/site-packages/jupyter_ydoc/ydoc.py", line 197, in set
    self._ycells.extend(t, [self.create_ycell(cell) for cell in cells])
  File "/opt/conda/lib/python3.9/site-packages/jupyter_ydoc/ydoc.py", line 197, in <listcomp>
    self._ycells.extend(t, [self.create_ycell(cell) for cell in cells])
  File "/opt/conda/lib/python3.9/site-packages/jupyter_ydoc/ydoc.py", line 127, in create_ycell
    cell["source"] = Y.YText(cell["source"])
TypeError: argument 'init': 'list' object cannot be converted to 'PyString'

Reproduce

example ipynb json:

{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4c8d2523-c9e8-4102-8949-8ec23e2be509",
   "metadata": {},
   "outputs": [],
   "source": [
    "print('hello world')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}

Expected behavior

Context

  • Operating System and version:
  • Browser and version:
  • Jupyter Server version:
Troubleshoot Output
Paste the output from running `jupyter troubleshoot` from the command line here.
You may want to sanitize the paths in the output.
Command Line Output
Paste the output from your command line running `jupyter lab` here, use `--debug` if possible.
Browser Output
Paste the output from your browser Javascript console here, if applicable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions