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

New REPL: python -q outputs unnecessary blank space on empty terminal #131743

Open
jfly opened this issue Mar 25, 2025 · 9 comments
Open

New REPL: python -q outputs unnecessary blank space on empty terminal #131743

jfly opened this issue Mar 25, 2025 · 9 comments
Labels
stdlib Python modules in the Lib dir topic-repl Related to the interactive shell type-bug An unexpected behavior, bug, or error

Comments

@jfly
Copy link

jfly commented Mar 25, 2025

Bug report

Bug description:

If I start the new REPL on a clear terminal, I get an unnecessary blank space.

clear; python -q

Image

Whereas this does not happen if I run the old ("basic") REPL:

clear; PYTHON_BASIC_REPL=1 python -q

Image

Analysis

I've tracked this down to these 2 lines of code: https://github.com/python/cpython/blob/3.13/Lib/_pyrepl/unix_console.py#L241-L242

self.__move(0, len(self.screen) - 1)
self.__write("\n")

I don't totally understand this code, but it certainly smells like there's a bug here when dealing with an empty screen (for example, if len(self.screen) == 0, are we trying to move the cursor to index -1?)

I'm not sure what the fix is here, though. I don't really understand this code: why are we moving up to a line just to move the cursor down a line afterwards? why can't we jump straight to where we want to be? I tried digging through the git history for answers, but it looks like this incantation dates back all the way to this initial commit to pypi/pyrepl. I'm not sure how to dig any further back in time.

CPython versions tested on:

3.13, 3.14, CPython main branch

Operating systems tested on:

Linux

I'm using Alacritty, in case that's relevant.

Linked PRs

@jfly jfly added the type-bug An unexpected behavior, bug, or error label Mar 25, 2025
@tomasr8 tomasr8 added the topic-repl Related to the interactive shell label Mar 25, 2025
@skirpichev
Copy link
Member

I'm using Alacritty, in case that's relevant.

I think so. I can't reproduce this in gterm.

@jfly
Copy link
Author

jfly commented Mar 26, 2025

@skirpichev, what is gterm? Is it gnome-terminal? I am able to reproduce the issue with gnome-terminal.

@skirpichev
Copy link
Member

I am able to reproduce the issue with gnome-terminal.

Hmm, my fault. It's important to run commands as one-liner's, i.e. clear;./python -q.

@donBarbos
Copy link
Contributor

donBarbos commented Mar 26, 2025

this is also reproduced on my system. i use kitty

It would be great to know what the behavior is on Windows

@donBarbos
Copy link
Contributor

it seems that these actions are not needed in some cases, so if we do this inside block if len(self.screen): the problem is not reproduced and the tests still pass (at least for me)

we also have same code in WondowsConsole.refresh method, i think we should fix that too

if no one minds i'll send PR, and it would be nice to make backport for 3.13

@jfly
Copy link
Author

jfly commented Mar 26, 2025

That sounds like a safe change to me, @donBarbos.

I'm curious though: can you explain why we ever need to do this? Why are we jumping 1 line above where we need to go just to go one 1 down right after? Why are we even jumping the cursor around at all? (I don't think we're redrawing the entire screen, are we?)

@donBarbos
Copy link
Contributor

for example when we want to move to the next line after entering : for some construction

but I'm not an expert :-) it's better to ask the author or some of core team

@jfly
Copy link
Author

jfly commented Mar 26, 2025

for example when we want to move to the next line after entering : for some construction

I still don't understand why we wouldn't jump straight to where we want to go. Why one above and then down?

@donBarbos
Copy link
Contributor

cc @pablogsal as author of new python repl

sorry for ping, do you mind?

@picnixz picnixz added the stdlib Python modules in the Lib dir label Mar 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir topic-repl Related to the interactive shell type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

5 participants