If a cell has an unexpected output_type, we get an UnboundLocalError, because a variable used is unassigned. The code in question is this block.
$ nbterm foo.ipynb
Traceback (most recent call last):
File "/Users/okokes/Notebooks/.dev/bin/nbterm", line 8, in <module>
sys.exit(cli())
File "/Users/okokes/Notebooks/.dev/lib/python3.9/site-packages/nbterm/nbterm.py", line 43, in cli
typer.run(main)
File "/Users/okokes/Notebooks/.dev/lib/python3.9/site-packages/typer/main.py", line 859, in run
app()
File "/Users/okokes/Notebooks/.dev/lib/python3.9/site-packages/typer/main.py", line 214, in __call__
return get_command(self)(*args, **kwargs)
File "/Users/okokes/Notebooks/.dev/lib/python3.9/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/Users/okokes/Notebooks/.dev/lib/python3.9/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/Users/okokes/Notebooks/.dev/lib/python3.9/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/Users/okokes/Notebooks/.dev/lib/python3.9/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/Users/okokes/Notebooks/.dev/lib/python3.9/site-packages/typer/main.py", line 497, in wrapper
return callback(**use_params) # type: ignore
File "/Users/okokes/Notebooks/.dev/lib/python3.9/site-packages/nbterm/nbterm.py", line 29, in main
nb = Notebook(notebook_path, no_kernel=no_kernel or False, save_path=save_path)
File "/Users/okokes/Notebooks/.dev/lib/python3.9/site-packages/nbterm/notebook.py", line 61, in __init__
self.read_nb()
File "/Users/okokes/Notebooks/.dev/lib/python3.9/site-packages/nbterm/format.py", line 15, in read_nb
self.cells = [
File "/Users/okokes/Notebooks/.dev/lib/python3.9/site-packages/nbterm/format.py", line 16, in <listcomp>
Cell(self, cell_json=cell_json) for cell_json in self.json["cells"]
File "/Users/okokes/Notebooks/.dev/lib/python3.9/site-packages/nbterm/cell.py", line 98, in __init__
output_text, output_height = get_output_text_and_height(
File "/Users/okokes/Notebooks/.dev/lib/python3.9/site-packages/nbterm/cell.py", line 45, in get_output_text_and_height
text_list.append(text)
UnboundLocalError: local variable 'text' referenced before assignment
If a cell has an unexpected
output_type
, we get an UnboundLocalError, because a variable used is unassigned. The code in question is this block.(output_type is
display_data
in my case)I have a fix ready, I'll submit it shortly.