bpython / bpython

bpython - A fancy curses interface to the Python interactive interpreter
https://bpython-interpreter.org/
Other
2.62k stars 239 forks source link

bpython crashes trying to print large object #1020

Closed vshesh closed 2 months ago

vshesh commented 3 months ago

Hi,

Long time user of bpython, first time I got an error:


Traceback (most recent call last):
  File "/usr/local/bin/bpython", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/usr/local/lib/python3.12/site-packages/bpython/curtsies.py", line 248, in main
    repl.mainloop(True, paste)
  File "/usr/local/lib/python3.12/site-packages/bpython/curtsies.py", line 181, in mainloop
    self.process_event_and_paint(e)
  File "/usr/local/lib/python3.12/site-packages/bpython/curtsies.py", line 151, in process_event_and_paint
    array, cursor_pos = self.paint()
                        ^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/bpython/curtsiesfrontend/repl.py", line 1610, in paint
    current_line = paint.paint_current_line(
                   ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/bpython/curtsiesfrontend/replpainter.py", line 50, in paint_current_line
    return fsarray(lines, width=columns)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/curtsies/formatstringarray.py", line 268, in fsarray
    raise ValueError(f"Those strings won't fit for width {width}")
ValueError: Those strings won't fit for width 101
Exception: bpython exited with 1
[tty 33], line 1: bpython

version information

$ bpython
bpython version 0.24 on top of Python 3.12.3 /usr/local/opt/python@3.12/bin/python3.12

I can json.dumps the large object, bpython will just crash on doing it itself though. I am guessing this is because it would take more than one whole screen to print out the object. having bpython die during a session when this happens is quite annoying - can this be fixed?

sebastinas commented 3 months ago

Please provide a way to reproduce the issue.

vshesh commented 3 months ago

here you go the error seems to stem from use of unicode in strings somehow printing the string directly is fine, but embedding it in an object causes issues

$ bpython
>>> def infer(*args):
...     r = []
...     for i in range(10):
...         r.append([{
...             'location': {'type': 'x̄ȳwhr', 'value': [0.12309123, 1.1231312, 2.123123, 3.123213]},
...         }])
...
...     return r
...
>>> infer()
sebastinas commented 2 months ago

This is a duplicate of https://github.com/bpython/curtsies/issues/173.