Skip to content

Certain unicode sequences cause a crash "ValueError: Those strings won't fit for width 88" #173

Description

@Andriamanitra

I ran into this issue by running the following in a standard width terminal:

bpython version 0.22.1 on top of Python 3.10.5 /home/mikko/tmp/venv/bin/python
>>> import html
>>> html.entities.html5
Traceback (most recent call last):
  File "/home/mikko/tmp/venv/bin/bpython", line 8, in <module>
    sys.exit(main())
  File "/home/mikko/tmp/venv/lib/python3.10/site-packages/bpython/curtsies.py", line 248, in main
    repl.mainloop(True, paste)
  File "/home/mikko/tmp/venv/lib/python3.10/site-packages/bpython/curtsies.py", line 181, in mainloop
    self.process_event_and_paint(e)
  File "/home/mikko/tmp/venv/lib/python3.10/site-packages/bpython/curtsies.py", line 151, in process_event_and_paint
    array, cursor_pos = self.paint()
  File "/home/mikko/tmp/venv/lib/python3.10/site-packages/bpython/curtsiesfrontend/repl.py", line 1489, in paint
    current_line = paint.paint_current_line(
  File "/home/mikko/tmp/venv/lib/python3.10/site-packages/bpython/curtsiesfrontend/replpainter.py", line 50, in paint_current_line
    return fsarray(lines, width=columns)
  File "/home/mikko/tmp/venv/lib/python3.10/site-packages/curtsies/formatstringarray.py", line 267, in fsarray
    raise ValueError(f"Those strings won't fit for width {width}")
ValueError: Those strings won't fit for width 88

Regular Python 3.10 interpreter has no issues displaying the same dict in the same terminal so I assume this is a bpython bug rather than something with how my terminal is set up. The issue seems to be with characters such as ∾̳ ("\u223e\u0333") that have length greater than 1 but are only rendered one character wide:

bpython version 0.22.1 on top of Python 3.10.5 /home/mikko/tmp/venv/bin/python
>>> import shutil
>>> '∾̳' * (shutil.get_terminal_size().columns // 2 - 1)
'∾̳∾̳∾̳∾̳∾̳∾̳∾̳∾̳∾̳∾̳∾̳∾̳∾̳∾̳∾̳∾̳∾̳∾̳∾̳∾̳∾̳∾̳∾̳∾̳∾̳∾̳∾̳∾̳∾̳∾̳∾̳∾̳∾̳∾̳∾̳∾̳∾̳∾̳∾̳∾̳∾̳∾̳∾̳'
>>> '∾̳' * (shutil.get_terminal_size().columns // 2)
Traceback (most recent call last):
  File "/home/mikko/tmp/venv/bin/bpython", line 8, in <module>
    sys.exit(main())
  File "/home/mikko/tmp/venv/lib/python3.10/site-packages/bpython/curtsies.py", line 248, in main
    repl.mainloop(True, paste)
  File "/home/mikko/tmp/venv/lib/python3.10/site-packages/bpython/curtsies.py", line 181, in mainloop
    self.process_event_and_paint(e)
  File "/home/mikko/tmp/venv/lib/python3.10/site-packages/bpython/curtsies.py", line 151, in process_event_and_paint
    array, cursor_pos = self.paint()
  File "/home/mikko/tmp/venv/lib/python3.10/site-packages/bpython/curtsiesfrontend/repl.py", line 1489, in paint
    current_line = paint.paint_current_line(
  File "/home/mikko/tmp/venv/lib/python3.10/site-packages/bpython/curtsiesfrontend/replpainter.py", line 50, in paint_current_line
    return fsarray(lines, width=columns)
  File "/home/mikko/tmp/venv/lib/python3.10/site-packages/curtsies/formatstringarray.py", line 267, in fsarray
    raise ValueError(f"Those strings won't fit for width {width}")
ValueError: Those strings won't fit for width 88

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions