Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Andriamanitra opened this issue Aug 3, 2022 · 1 comment
Labels

Comments

@Andriamanitra
Copy link

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
@sebastinas sebastinas transferred this issue from bpython/bpython Aug 4, 2022
@sebastinas sebastinas added the bug label Aug 4, 2022
@sebastinas
Copy link
Contributor

I believe this is a bug in fsarray. It checks the length of the string with len instead of wcswidth.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants