]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-43084: Return bool instead of int from curses.window.enclose() (GH-24398)
authorSerhiy Storchaka <storchaka@gmail.com>
Mon, 5 Apr 2021 13:50:24 +0000 (16:50 +0300)
committerGitHub <noreply@github.com>
Mon, 5 Apr 2021 13:50:24 +0000 (16:50 +0300)
Doc/library/curses.rst
Lib/test/test_curses.py
Misc/NEWS.d/next/Library/2021-01-31-17-31-13.bpo-43084.i8nLpK.rst [new file with mode: 0644]
Modules/_cursesmodule.c
Modules/clinic/_cursesmodule.c.h

index f55bb034b559bfbb6dc29e7ed5868df4e49a8449..efbece437af2dd591011e13301b98c4f131728fb 100644 (file)
@@ -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
 
index 7ce0461ab54f2df4928ab2b28437bbc0e206988e..280a9dc0eedfcefe48d4ed44c6b477f9749ec7aa 100644 (file)
@@ -566,13 +566,12 @@ class TestCurses(unittest.TestCase):
     @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)
diff --git a/Misc/NEWS.d/next/Library/2021-01-31-17-31-13.bpo-43084.i8nLpK.rst b/Misc/NEWS.d/next/Library/2021-01-31-17-31-13.bpo-43084.i8nLpK.rst
new file mode 100644 (file)
index 0000000..bdab5d9
--- /dev/null
@@ -0,0 +1,2 @@
+:func:`curses.window.enclose` returns now ``True`` or ``False`` (as was
+documented) instead of ``1`` or ``0``.
index 3df9f506052d3a5a7a8282bd75ac300e528932ce..d221cf1a92520c4b8512be912599e79cd192d5c4 100644 (file)
@@ -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.
@@ -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
 
index e46a8e3d0b23e6844e699065a0d624065edb093b..9c9611685b78edf8ffc8bd1cf01528c1269e44f9 100644 (file)
@@ -689,7 +689,7 @@ PyDoc_STRVAR(_curses_window_enclose__doc__,
 #define _CURSES_WINDOW_ENCLOSE_METHODDEF    \
     {"enclose", (PyCFunction)(void(*)(void))_curses_window_enclose, METH_FASTCALL, _curses_window_enclose__doc__},
 
-static long
+static PyObject *
 _curses_window_enclose_impl(PyCursesWindowObject *self, int y, int x);
 
 static PyObject *
@@ -698,7 +698,6 @@ _curses_window_enclose(PyCursesWindowObject *self, PyObject *const *args, Py_ssi
     PyObject *return_value = NULL;
     int y;
     int x;
-    long _return_value;
 
     if (!_PyArg_CheckPositional("enclose", nargs, 2, 2)) {
         goto exit;
@@ -711,11 +710,7 @@ _curses_window_enclose(PyCursesWindowObject *self, PyObject *const *args, Py_ssi
     if (x == -1 && PyErr_Occurred()) {
         goto exit;
     }
-    _return_value = _curses_window_enclose_impl(self, y, x);
-    if ((_return_value == -1) && PyErr_Occurred()) {
-        goto exit;
-    }
-    return_value = PyLong_FromLong(_return_value);
+    return_value = _curses_window_enclose_impl(self, y, x);
 
 exit:
     return return_value;
@@ -4289,4 +4284,4 @@ _curses_has_extended_color_support(PyObject *module, PyObject *Py_UNUSED(ignored
 #ifndef _CURSES_USE_DEFAULT_COLORS_METHODDEF
     #define _CURSES_USE_DEFAULT_COLORS_METHODDEF
 #endif /* !defined(_CURSES_USE_DEFAULT_COLORS_METHODDEF) */
-/*[clinic end generated code: output=ae6559aa61200289 input=a9049054013a1b77]*/
+/*[clinic end generated code: output=9efc9943a3ac3741 input=a9049054013a1b77]*/