Skip to content

Commit 6af6165

Browse files
authored
gh-154788: Make curses window.getparent() unconditional (GH-154789)
getparent() calls no curses function, it returns the window's stored parent, but it was compiled only when the ncurses extension functions were present. Close the guard after getscrreg(), which does need it. The test moves out of test_state_getters, which is gated on is_scrollok(), so that getparent() is covered on backends without the extensions.
1 parent 8b048eb commit 6af6165

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

Lib/test/test_curses.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,14 @@ def test_subwindows_references(self):
278278
del win2
279279
gc_collect()
280280

281+
def test_getparent(self):
282+
# getparent() calls no curses function, so it works with any backend
283+
# and is not gated like the is_*() getters below.
284+
stdscr = self.stdscr
285+
self.assertIsNone(stdscr.getparent())
286+
sub = stdscr.subwin(3, 3, 0, 0)
287+
self.assertIs(sub.getparent(), stdscr)
288+
281289
def test_dupwin(self):
282290
win = curses.newwin(5, 10, 2, 3)
283291
win.addstr(0, 0, 'ABCDE')
@@ -1771,13 +1779,11 @@ def test_state_getters(self):
17711779
stdscr.setscrreg(5, 10)
17721780
self.assertEqual(stdscr.getscrreg(), (5, 10))
17731781

1774-
# is_pad()/is_subwin()/getparent().
1782+
# is_pad()/is_subwin().
17751783
self.assertIs(stdscr.is_pad(), False)
17761784
self.assertIs(stdscr.is_subwin(), False)
1777-
self.assertIsNone(stdscr.getparent())
17781785
sub = stdscr.subwin(3, 3, 0, 0)
17791786
self.assertIs(sub.is_subwin(), True)
1780-
self.assertIs(sub.getparent(), stdscr)
17811787
pad = curses.newpad(5, 5)
17821788
self.assertIs(pad.is_pad(), True)
17831789

Modules/_cursesmodule.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1936,6 +1936,7 @@ PyCursesWindow_getscrreg(PyObject *op, PyObject *Py_UNUSED(ignored))
19361936
}
19371937
return Py_BuildValue("(ii)", top, bottom);
19381938
}
1939+
#endif /* NCURSES_EXT_FUNCS >= 20110404 || PDCURSES */
19391940

19401941
static PyObject *
19411942
PyCursesWindow_getparent(PyObject *op, PyObject *Py_UNUSED(ignored))
@@ -1948,7 +1949,6 @@ PyCursesWindow_getparent(PyObject *op, PyObject *Py_UNUSED(ignored))
19481949
}
19491950
return Py_NewRef((PyObject *)self->orig);
19501951
}
1951-
#endif /* NCURSES_EXT_FUNCS >= 20110404 || PDCURSES */
19521952

19531953
Window_NoArgNoReturnVoidFunction(wsyncup)
19541954
Window_NoArgNoReturnVoidFunction(wsyncdown)
@@ -5061,11 +5061,9 @@ static PyMethodDef PyCursesWindow_methods[] = {
50615061
{"getmaxyx", PyCursesWindow_getmaxyx, METH_NOARGS,
50625062
"getmaxyx($self, /)\n--\n\n"
50635063
"Return a tuple (y, x) of the window height and width."},
5064-
#if (defined(NCURSES_EXT_FUNCS) && NCURSES_EXT_FUNCS >= 20110404) || defined(PDCURSES)
50655064
{"getparent", PyCursesWindow_getparent, METH_NOARGS,
50665065
"getparent($self, /)\n--\n\n"
50675066
"Return the parent window, or None if this is not a subwindow."},
5068-
#endif
50695067
{"getparyx", PyCursesWindow_getparyx, METH_NOARGS,
50705068
"getparyx($self, /)\n--\n\n"
50715069
"Return (y, x) relative to the parent window, or (-1, -1) if none."},

0 commit comments

Comments
 (0)