8000 gh-125843: indicate which C function caused a `curses.error` (#125844) · python/cpython@ee36db5 · GitHub
[go: up one dir, main page]

Skip to content

Commit ee36db5

Browse files
authored
gh-125843: indicate which C function caused a curses.error (#125844)
- Rename error helpers with a `curses_set_error_*` prefix instead of `PyCurses*`. - Cleanly report both NULL and ERR cases. - Raise `curses.error` in `is_linetouched` instead of a `TypeError`.
1 parent c31547a commit ee36db5

File tree

4 files changed

+367
-180
lines changed

4 files changed

+367
-180
lines changed

Include/py_curses.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,13 @@ static void **PyCurses_API;
109109
static const char catchall_ERR[] = "curses function returned ERR";
110110
static const char catchall_NULL[] = "curses function returned NULL";
111111

112+
#if defined(CURSES_MODULE) || defined(CURSES_PANEL_MODULE)
113+
/* Error messages shared by the curses package */
114+
# define CURSES_ERROR_FORMAT "%s() returned %s"
115+
# define CURSES_ERROR_VERBOSE_FORMAT "%s() (called by %s()) returned %s"
116+
# define CURSES_ERROR_MUST_CALL_FORMAT "must call %s() first"
117+
#endif
118+
112119
#ifdef __cplusplus
113120
}
114121
#endif

Lib/test/test_curses.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ def test_use_env(self):
130130
curses.use_env(False)
131131
curses.use_env(True)
132132

133+
def test_error(self):
134+
self.assertIsSubclass(curses.error, Exception)
135+
133136
def test_create_windows(self):
134137
win = curses.newwin(5, 10)
135138
self.assertEqual(win.getbegyx(), (0, 0))
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
If possible, indicate which :mod:`curses` C function or macro is responsible
2+
for raising a :exc:`curses.error` exception. Patch by Bénédikt Tran.

0 commit comments

Comments
 (0)
0