GeezerVison is showing github.com — `AssertionError` when `print()`ing carriage return character · Issue #900 · bpython/bpython
AssertionError when print()ing carriage return character #900
DescriptionThe most succinct example I have found is this:
$ bpython
bpython version 0.21 on top of Python 3.9.4 /Users/hop/Library/PipXEnvs/venvs/bpython/bin/python
>>> print('', end='\r')
Traceback (most recent call last):
File "/Users/hop/bin/bpython", line 8, in <module>
sys.exit(main())
File "/Users/hop/Library/PipXEnvs/venvs/bpython/lib/python3.9/site-packages/bpython/curtsies.py", line 201, in main
exit_value = repl.mainloop(True, paste)
File "/Users/hop/Library/PipXEnvs/venvs/bpython/lib/python3.9/site-packages/bpython/curtsies.py", line 121, in mainloop
self.process_event_and_paint(e)
File "/Users/hop/Library/PipXEnvs/venvs/bpython/lib/python3.9/site-packages/bpython/curtsies.py", line 95, in process_event_and_paint
array, cursor_pos = self.paint()
File "/Users/hop/Library/PipXEnvs/venvs/bpython/lib/python3.9/site-packages/bpython/curtsiesfrontend/repl.py", line 1610, in paint
assert cursor_row >= 0 and cursor_column >= 0, (
AssertionError: (-1, 79, 5, 0, 0)
Another variation leading to a crash is print('\r', end='').
print('\r\n', end='') does not crash, while print('\n\r', end='') will.
Reacted by Ian Chamberlain and Mehedi Hasan Activityarian-deimling commented on Oct 2, 2021 This issue has the same root cause as #915. eabase commented on Feb 2, 2022 This issue is over 8 months old, why has nothing been done here?
I use these printing methods all the time, and this is the only reason why I am not using bpython atm. ian-h-chamberlain commented on Sep 21, 2023 Although print('\r\n') doesn't assert, it also seems to have some very odd behavior with how the output is rendered, which I can reproduce by printing a multiline string several times (bpython version 0.24 on top of Python 3.11.5 on macOS). The issue goes away if I .replace("\r", "") on the string before printing.
Edit: more info about my environment. I can attach full logs if needed.
2023-09-21 10:21:15,662: bpython.args: INFO: Starting bpython 0.24
2023-09-21 10:21:15,663: bpython.args: INFO: Python /usr/local/Cellar/bpython/0.24_1/libexec/bin/python: sys.version_info(major=3, minor=11, micro=5, releaselevel='final', serial=0)
2023-09-21 10:21:15,663: bpython.args: INFO: curtsies: 0.4.1
2023-09-21 10:21:15,663: bpython.args: INFO: cwcwidth: 0.1.8
2023-09-21 10:21:15,663: bpython.args: INFO: greenlet: 2.0.2
2023-09-21 10:21:15,663: bpython.args: INFO: pygments: 2.16.1
2023-09-21 10:21:15,663: bpython.args: INFO: pyxdg: 0.28
2023-09-21 10:21:15,663: bpython.args: INFO: requests: 2.31.0
2023-09-21 10:21:15,663: bpython.args: INFO: pyperclip: not available
2023-09-21 10:21:15,664: bpython.args: INFO: jedi: not available
2023-09-21 10:21:15,664: bpython.args: INFO: watchdog: not available
2023-09-21 10:21:15,664: bpython.args: INFO: environment:
2023-09-21 10:21:15,664: bpython.args: INFO: LANG: en_US.UTF-8
2023-09-21 10:21:15,664: bpython.args: INFO: LC_TERMINAL: iTerm2
2023-09-21 10:21:15,664: bpython.args: INFO: LC_TERMINAL_VERSION: 3.4.20
2023-09-21 10:21:15,664: bpython.args: INFO: TERM: xterm-256color-italic
Each of these is exactly the same string, but the output only appears once the input prompt has gotten low enough in my terminal to scroll it. (tested on iTerm2 and VSCode builtin terminal).

Seems this issue has been open a while and #915 is closed, but mentions that it might be a curtsies issue? For now just removing \r from strings seems to be a workaround for me, but if you actually need to print carriage returns I could see this being an issue.
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|