Skip to content

Commit

Permalink
bpo-43084: Return bool instead of int from curses.window.enclose() (p…
Browse files Browse the repository at this point in the history
  • Loading branch information
serhiy-storchaka authored Apr 5, 2021
1 parent c8e5eb9 commit b1dc1aa
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 19 deletions.
3 changes: 3 additions & 0 deletions Doc/library/curses.rst
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,9 @@ the following methods and attributes:
determining what subset of the screen windows enclose the location of a mouse
event.

.. versionchanged:: 3.10
Previously it returned ``1`` or ``0`` instead of ``True`` or ``False``.


.. attribute:: window.encoding

Expand Down
13 changes: 6 additions & 7 deletions Lib/test/test_curses.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,13 +566,12 @@ def test_resize(self):
@requires_curses_window_meth('enclose')
def test_enclose(self):
win = curses.newwin(5, 15, 2, 5)
# TODO: Return bool instead of 1/0
self.assertTrue(win.enclose(2, 5))
self.assertFalse(win.enclose(1, 5))
self.assertFalse(win.enclose(2, 4))
self.assertTrue(win.enclose(6, 19))
self.assertFalse(win.enclose(7, 19))
self.assertFalse(win.enclose(6, 20))
self.assertIs(win.enclose(2, 5), True)
self.assertIs(win.enclose(1, 5), False)
self.assertIs(win.enclose(2, 4), False)
self.assertIs(win.enclose(6, 19), True)
self.assertIs(win.enclose(7, 19), False)
self.assertIs(win.enclose(6, 20), False)

def test_putwin(self):
win = curses.newwin(5, 12, 1, 2)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
:func:`curses.window.enclose` returns now ``True`` or ``False`` (as was
documented) instead of ``1`` or ``0``.
8 changes: 4 additions & 4 deletions Modules/_cursesmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -1343,7 +1343,7 @@ _curses_window_echochar_impl(PyCursesWindowObject *self, PyObject *ch,

#ifdef NCURSES_MOUSE_VERSION
/*[clinic input]
_curses.window.enclose -> long
_curses.window.enclose
y: int
Y-coordinate.
Expand All @@ -1354,11 +1354,11 @@ _curses.window.enclose -> long
Return True if the screen-relative coordinates are enclosed by the window.
[clinic start generated code]*/

static long
static PyObject *
_curses_window_enclose_impl(PyCursesWindowObject *self, int y, int x)
/*[clinic end generated code: output=5251c961cbe3df63 input=dfe1d9d4d05d8642]*/
/*[clinic end generated code: output=8679beef50502648 input=4fd3355d723f7bc9]*/
{
return wenclose(self->win, y, x);
return PyBool_FromLong(wenclose(self->win, y, x));
}
#endif

Expand Down
11 changes: 3 additions & 8 deletions Modules/clinic/_cursesmodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b1dc1aa

Please sign in to comment.