8000 gh-134210: handle signals in `_curses.window.getch` by picnixz · Pull Request #134326 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-134210: handle signals in _curses.window.getch #134326

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

picnixz
Copy link
Member
@picnixz picnixz commented May 20, 2025

@vstinner
Copy link
Member
vstinner commented May 20, 2025

I tried this change with the script:

from curses import wrapper
import ctypes

def main(window):
    window.nodelay(True)
    return window.getch()

print(wrapper(main))

Before (without this change), it displays -1.

After (with this change), it fails with the exception: _curses.error: wgetch() (called by getch()): no input.

So this change is backward incompatible. Is it deliberate?

@picnixz
Copy link
Member Author
picnixz commented May 20, 2025

Hum. No it's not meant to be broken!

Only the signals should be handled, but otherwise we shouldn't raise an exception.

@picnixz
Copy link
Member Author
picnixz commented May 20, 2025

Now I am bit conflicted. Ideally, we should return -1 for everything or raise an exception as in the other functions. I don't know why it was historically chosen to return -1 for getch but not for get_wch in no-delay mode.

However, since I don't want to break stuff, I don't know how we can make a smooth transition, except by raising a warning before returning -1.

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

Successfully merging this pull request may close these issues.

2 participants
0