Skip to content

AssertionError when print()ing carriage return character #900

Open

Description

@hop

The 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.

Activity

  1. arian-deimling commented on Oct 2, 2021

    @arian-deimling
    Contributor

    This issue has the same root cause as #915.

  2. eabase commented on Feb 2, 2022

    @eabase

    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.

  3. ian-h-chamberlain commented on Sep 21, 2023

    @ian-h-chamberlain

    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).

    Screenshot 2023-09-21 at 10 12 45

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions