8000 gh-133575: eliminate legacy checks in `curses.__init__` by picnixz · Pull Request #133576 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-133575: eliminate legacy checks in curses.__init__ #133576

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

Merged
merged 1 commit into from
May 7, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
modernize curses.__init__ code
  • Loading branch information
picnixz committed May 7, 2025
commit 6232abb86e582460c2fbc501847459e3cefab2ab
17 changes: 7 additions & 10 deletions Lib/curses/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ def initscr():
fd=_sys.__stdout__.fileno())
stdscr = _curses.initscr()
for key, value in _curses.__dict__.items():
if key[0:4] == 'ACS_' or key in ('LINES', 'COLS'):
if key.startswith('ACS_') or key in ('LINES', 'COLS'):
setattr(curses, key, value)

return stdscr

# This is a similar wrapper for start_color(), which adds the COLORS and
Expand All @@ -41,12 +40,9 @@ def initscr():

def start_color():
import _curses, curses
retval = _curses.start_color()
if hasattr(_curses, 'COLORS'):
curses.COLORS = _curses.COLORS
if hasattr(_curses, 'COLOR_PAIRS'):
curses.COLOR_PAIRS = _curses.COLOR_PAIRS
return retval
_curses.start_color()
curses.COLORS = _curses.COLORS
curses.COLOR_PAIRS = _curses.COLOR_PAIRS

# Import Python has_key() implementation if _curses doesn't contain has_key()

Expand Down Expand Up @@ -85,10 +81,11 @@ def wrapper(func, /, *args, **kwds):
# Start color, too. Harmless if the terminal doesn't have
# color; user can test with has_color() later on. The try/catch
# works around a minor bit of over-conscientiousness in the curses
# module -- the error return from C start_color() is ignorable.
# module -- the error return from C start_color() is ignorable,
# unless they are raised by the interpreter due to other issues.
try:
start_color()
except:
except _curses.error:
pass

return func(stdscr, *args, **kwds)
Expand Down
Loading
0