Skip to content

Commit a054af6

Browse files
authored
gh-133575: eliminate legacy checks in Lib/curses/__init__.py (#133576)
1 parent d9b0b07 commit a054af6

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

Lib/curses/__init__.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@ def initscr():
3030
fd=_sys.__stdout__.fileno())
3131
stdscr = _curses.initscr()
3232
for key, value in _curses.__dict__.items():
33-
if key[0:4] == 'ACS_' or key in ('LINES', 'COLS'):
33+
if key.startswith('ACS_') or key in ('LINES', 'COLS'):
3434
setattr(curses, key, value)
35-
3635
return stdscr
3736

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

4241
def start_color():
4342
import _curses, curses
44-
retval = _curses.start_color()
45-
if hasattr(_curses, 'COLORS'):
46-
curses.COLORS = _curses.COLORS
47-
if hasattr(_curses, 'COLOR_PAIRS'):
48-
curses.COLOR_PAIRS = _curses.COLOR_PAIRS
49-
return retval
43+
_curses.start_color()
44+
curses.COLORS = _curses.COLORS
45+
curses.COLOR_PAIRS = _curses.COLOR_PAIRS
5046

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

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

9491
return func(stdscr, *args, **kwds)

0 commit comments

Comments
 (0)