]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.14] gh-153422: Assert bool return type in tkinter tests (GH-153429) (GH-153439...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Thu, 9 Jul 2026 15:45:11 +0000 (17:45 +0200)
committerGitHub <noreply@github.com>
Thu, 9 Jul 2026 15:45:11 +0000 (15:45 +0000)
The tests for PhotoImage.transparency_get(), Text.debug() and
Treeview.exists() now assert the exact bool type, and the documentation
and docstrings use "true"/"false" instead of "1"/"0".
(cherry picked from commit 1604c80008d72b4c9a5bd789900ecf9aff402c1e)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Doc/library/tkinter.rst
Lib/test/test_tkinter/test_images.py
Lib/test/test_tkinter/test_text.py
Lib/test/test_ttk/test_widgets.py
Lib/tkinter/ttk.py

index 2fc19b8dca4f02d3608255a88b15e3dc353aa1a9..ec0ec48a5959af8ee39a147d9249d42edfe364ae 100644 (file)
@@ -1986,7 +1986,7 @@ Base and mixin classes
 
    .. method:: winfo_exists()
 
-      Return ``1`` if the widget exists, ``0`` otherwise.
+      Return true if the widget exists, false otherwise.
 
    .. method:: winfo_fpixels(number)
 
@@ -2025,7 +2025,7 @@ Base and mixin classes
 
    .. method:: winfo_ismapped()
 
-      Return ``1`` if the widget is currently mapped, ``0`` otherwise.
+      Return true if the widget is currently mapped, false otherwise.
 
    .. method:: winfo_manager()
 
@@ -2156,8 +2156,8 @@ Base and mixin classes
 
    .. method:: winfo_viewable()
 
-      Return ``1`` if the widget and all of its ancestors up through the
-      nearest toplevel window are mapped, ``0`` otherwise.
+      Return true if the widget and all of its ancestors up through the
+      nearest toplevel window are mapped, false otherwise.
 
    .. method:: winfo_visual()
 
@@ -5534,7 +5534,7 @@ Widget classes
    .. method:: edit_modified(arg=None)
 
       If *arg* is omitted, return the current state of the modified flag as
-      ``0`` or ``1``; the flag is set automatically whenever the text is
+      true or false; the flag is set automatically whenever the text is
       inserted or deleted.
       Otherwise set the flag to the boolean *arg*.
 
index fbc478b45172d548f70ac2032da5d4ef50220f8e..eb5794d391e758986af5b7eb8d5e8994d1f5755a 100644 (file)
@@ -647,12 +647,12 @@ class PhotoImageTest(AbstractTkTest, unittest.TestCase):
 
     def test_transparency(self):
         image = self.create()
-        self.assertEqual(image.transparency_get(0, 0), True)
-        self.assertEqual(image.transparency_get(4, 6), False)
+        self.assertIs(image.transparency_get(0, 0), True)
+        self.assertIs(image.transparency_get(4, 6), False)
         image.transparency_set(4, 6, True)
-        self.assertEqual(image.transparency_get(4, 6), True)
+        self.assertIs(image.transparency_get(4, 6), True)
         image.transparency_set(4, 6, False)
-        self.assertEqual(image.transparency_get(4, 6), False)
+        self.assertIs(image.transparency_get(4, 6), False)
         self.assertRaises(tkinter.TclError, image.transparency_get, -1, 0)
         self.assertRaises(tkinter.TclError, image.transparency_get, 16, 0)
         self.assertRaises(tkinter.TclError, image.transparency_set, -1, 0, True)
index 8177750b3ba3323e86bfe5a7a3dc6181ddc442aa..acbee1acad633e4994b9bc91f6cbca15ea8d1143 100644 (file)
@@ -18,10 +18,10 @@ class TextTest(AbstractTkTest, unittest.TestCase):
         text = self.text
         olddebug = text.debug()
         try:
-            text.debug(0)
-            self.assertEqual(text.debug(), 0)
-            text.debug(1)
-            self.assertEqual(text.debug(), 1)
+            text.debug(False)
+            self.assertIs(text.debug(), False)
+            text.debug(True)
+            self.assertIs(text.debug(), True)
         finally:
             text.debug(olddebug)
             self.assertEqual(text.debug(), olddebug)
index ac4a833a0b6b84dc5502cd3ac259f87e7970c221..6d997f9a8e86d0a561a1fa77071460f0ce21965f 100644 (file)
@@ -1680,9 +1680,9 @@ class TreeviewTest(AbstractWidgetTest, unittest.TestCase):
         self.assertEqual(self.tv.get_children(item_id), ())
 
     def test_exists(self):
-        self.assertEqual(self.tv.exists('something'), False)
-        self.assertEqual(self.tv.exists(''), True)
-        self.assertEqual(self.tv.exists({}), False)
+        self.assertIs(self.tv.exists('something'), False)
+        self.assertIs(self.tv.exists(''), True)
+        self.assertIs(self.tv.exists({}), False)
 
         # the following will make a tk.call equivalent to
         # tk.call(treeview, "exists") which should result in an error
index b3114a4666579d79ecd6355de63da053f078359c..e002ac8cfd0b641746821fa2ab400fe4d634027b 100644 (file)
@@ -1485,8 +1485,8 @@ class Treeview(Widget, tkinter.XView, tkinter.YView):
 
 
     def tag_has(self, tagname, item=None):
-        """If item is specified, returns 1 or 0 depending on whether the
-        specified item has the given tagname. Otherwise, returns a list of
+        """If item is specified, returns True if the specified item has the
+        given tagname, False otherwise. Otherwise, returns a list of
         all items which have the specified tag.
 
         * Availability: Tk 8.6"""