Skip to content

Commit 30dde1e

Browse files
authored
gh-133579: consistently report C curses function failures (#134327)
Some curses module-level functions and window methods now raise a `curses.error` when a call to a C curses function fails: - Module-level functions: assume_default_colors, baudrate, cbreak, echo, longname, initscr, nl, raw, termattrs, termname, and unctrl. - Window methods: addch, addnstr, addstr, border, box, chgat, getbkgd, inch, insstr, and insnstr. In addition, `curses.window.refresh` and `curses.window.noutrefresh` now raise a `TypeError` instead of a `curses.error` when called with an incorrect number of arguments for pads. See also ee36db5 for similar changes.
1 parent 604f835 commit 30dde1e

File tree

6 files changed

+192
-93
lines changed

6 files changed

+192
-93
lines changed

Doc/howto/curses.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ your terminal won't be left in a funny state on exception and you'll be
161161
able to read the exception's message and traceback.
162162

163163

164+
.. _windows-and-pads:
165+
164166
Windows and Pads
165167
================
166168

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
:ref:`curses.window <curses-window-objects>`: Consistently report failures
2+
of curses C API calls in Window methods by raising a :exc:`curses.error`.
3+
This affects :meth:`~curses.window.addch`, :meth:`~curses.window.addnstr`,
4+
:meth:`~curses.window.addstr`, :meth:`~curses.window.border`,
5+
:meth:`~curses.window.box`, :meth:`~curses.window.chgat`,
6+
:meth:`~curses.window.getbkgd`, :meth:`~curses.window.inch`,
7+
:meth:`~curses.window.insstr` and :meth:`~curses.window.insnstr`.
8+
Patch by Bénédikt Tran.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
:meth:`curses.window.refresh` and :meth:`curses.window.noutrefresh` now raise
2+
a :exc:`TypeError` instead of :exc:`curses.error` when called with an incorrect
3+
number of arguments for :ref:`pads <windows-and-pads>`. Patch by Bénédikt Tran.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
:mod:`curses`: Consistently report failures of curses C API calls in
2+
module-level methods by raising a :exc:`curses.error`. This affects
3+
:func:`~curses.assume_default_colors`, :func:`~curses.baudrate`,
4+
:func:`~curses.cbreak`, :func:`~curses.echo`, :func:`~curses.longname`,
5+
:func:`~curses.initscr`, :func:`~curses.nl`, :func:`~curses.raw`,
6+
:func:`~curses.termattrs`, :func:`~curses.termname` and :func:`~curses.unctrl`.
7+
Patch by Bénédikt Tran.

0 commit comments

Comments
 (0)