Skip to content

Commit 80a5509

Browse files
committed
gh-154788: Make curses window.getparent() unconditional
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 85c8bce commit 80a5509

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
@@ -1718,6 +1718,14 @@ def test_input_options(self):
17181718
stdscr.timeout(0)
17191719
stdscr.timeout(5)
17201720

1721+
def test_getparent(self):
1722+
# getparent() calls no curses function, so it works with any backend
1723+
# and is not gated like the is_*() getters below.
1724+
stdscr = self.stdscr
1725+
self.assertIsNone(stdscr.getparent())
1726+
sub = stdscr.subwin(3, 3, 0, 0)
1727+
self.assertIs(sub.getparent(), stdscr)
1728+
17211729
@requires_curses_window_meth('is_scrollok')
17221730
def test_state_getters(self):
17231731
stdscr = self.stdscr
@@ -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
@@ -1870,6 +1870,7 @@ PyCursesWindow_getscrreg(PyObject *op, PyObject *Py_UNUSED(ignored))
18701870
}
18711871
return Py_BuildValue("(ii)", top, bottom);
18721872
}
1873+
#endif /* NCURSES_EXT_FUNCS >= 20110404 || PDCURSES */
18731874

18741875
static PyObject *
18751876
PyCursesWindow_getparent(PyObject *op, PyObject *Py_UNUSED(ignored))
@@ -1882,7 +1883,6 @@ PyCursesWindow_getparent(PyObject *op, PyObject *Py_UNUSED(ignored))
18821883
}
18831884
return Py_NewRef((PyObject *)self->orig);
18841885
}
1885-
#endif /* NCURSES_EXT_FUNCS >= 20110404 || PDCURSES */
18861886

18871887
Window_NoArgNoReturnVoidFunction(wsyncup)
18881888
Window_NoArgNoReturnVoidFunction(wsyncdown)
@@ -4963,11 +4963,9 @@ static PyMethodDef PyCursesWindow_methods[] = {
49634963
{"getmaxyx", PyCursesWindow_getmaxyx, METH_NOARGS,
49644964
"getmaxyx($self, /)\n--\n\n"
49654965
"Return a tuple (y, x) of the window height and width."},
4966-
#if (defined(NCURSES_EXT_FUNCS) && NCURSES_EXT_FUNCS >= 20110404) || defined(PDCURSES)
49674966
{"getparent", PyCursesWindow_getparent, METH_NOARGS,
49684967
"getparent($self, /)\n--\n\n"
49694968
"Return the parent window, or None if this is not a subwindow."},
4970-
#endif
49714969
{"getparyx", PyCursesWindow_getparyx, METH_NOARGS,
49724970
"getparyx($self, /)\n--\n\n"
49734971
"Return (y, x) relative to the parent window, or (-1, -1) if none."},

0 commit comments

Comments
 (0)