From 89266fa516f2304796062d16e76253cf23fa4543 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Thu, 9 Jul 2026 18:16:50 +0300 Subject: [PATCH] [3.15] gh-153422: Assert bool return type in tkinter tests (GH-153429) (GH-153439) 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 Co-authored-by: Claude Opus 4.8 --- Doc/library/tkinter.rst | 10 +++++----- Lib/test/test_tkinter/test_images.py | 8 ++++---- Lib/test/test_tkinter/test_text.py | 8 ++++---- Lib/test/test_ttk/test_widgets.py | 6 +++--- Lib/tkinter/ttk.py | 4 ++-- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/Doc/library/tkinter.rst b/Doc/library/tkinter.rst index aff8c3ed5d2b15..a0e77095658a4d 100644 --- a/Doc/library/tkinter.rst +++ b/Doc/library/tkinter.rst @@ -1981,7 +1981,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) @@ -2020,7 +2020,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() @@ -2151,8 +2151,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() @@ -5526,7 +5526,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*. diff --git a/Lib/test/test_tkinter/test_images.py b/Lib/test/test_tkinter/test_images.py index fbc478b45172d5..eb5794d391e758 100644 --- a/Lib/test/test_tkinter/test_images.py +++ b/Lib/test/test_tkinter/test_images.py @@ -647,12 +647,12 @@ def test_data(self): 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) diff --git a/Lib/test/test_tkinter/test_text.py b/Lib/test/test_tkinter/test_text.py index 8177750b3ba332..acbee1acad633e 100644 --- a/Lib/test/test_tkinter/test_text.py +++ b/Lib/test/test_tkinter/test_text.py @@ -18,10 +18,10 @@ def test_debug(self): 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) diff --git a/Lib/test/test_ttk/test_widgets.py b/Lib/test/test_ttk/test_widgets.py index 5054ad8b9adf3f..1b8fc7c1d8bb0d 100644 --- a/Lib/test/test_ttk/test_widgets.py +++ b/Lib/test/test_ttk/test_widgets.py @@ -1641,9 +1641,9 @@ def test_detach_reattach(self): 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 diff --git a/Lib/tkinter/ttk.py b/Lib/tkinter/ttk.py index 3233c8973a8078..9d34e1fd8e7361 100644 --- a/Lib/tkinter/ttk.py +++ b/Lib/tkinter/ttk.py @@ -1483,8 +1483,8 @@ def tag_configure(self, tagname, option=None, **kw): 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"""