Skip to content

Commit b6751fa

Browse files
[3.15] gh-153422: Assert bool return type in tkinter tests (GH-153429)
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". Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 6404803 commit b6751fa

5 files changed

Lines changed: 18 additions & 18 deletions

File tree

Doc/library/tkinter.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2015,7 +2015,7 @@ Base and mixin classes
20152015

20162016
.. method:: winfo_exists()
20172017

2018-
Return ``1`` if the widget exists, ``0`` otherwise.
2018+
Return true if the widget exists, false otherwise.
20192019

20202020
.. method:: winfo_fpixels(number)
20212021

@@ -2054,7 +2054,7 @@ Base and mixin classes
20542054

20552055
.. method:: winfo_ismapped()
20562056

2057-
Return ``1`` if the widget is currently mapped, ``0`` otherwise.
2057+
Return true if the widget is currently mapped, false otherwise.
20582058

20592059
.. method:: winfo_manager()
20602060

@@ -2185,8 +2185,8 @@ Base and mixin classes
21852185

21862186
.. method:: winfo_viewable()
21872187

2188-
Return ``1`` if the widget and all of its ancestors up through the
2189-
nearest toplevel window are mapped, ``0`` otherwise.
2188+
Return true if the widget and all of its ancestors up through the
2189+
nearest toplevel window are mapped, false otherwise.
21902190

21912191
.. method:: winfo_visual()
21922192

@@ -5591,7 +5591,7 @@ Widget classes
55915591
.. method:: edit_modified(arg=None)
55925592

55935593
If *arg* is omitted, return the current state of the modified flag as
5594-
``0`` or ``1``; the flag is set automatically whenever the text is
5594+
true or false; the flag is set automatically whenever the text is
55955595
inserted or deleted.
55965596
Otherwise set the flag to the boolean *arg*.
55975597

Lib/test/test_tkinter/test_images.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -655,12 +655,12 @@ def test_data(self):
655655

656656
def test_transparency(self):
657657
image = self.create()
658-
self.assertEqual(image.transparency_get(0, 0), True)
659-
self.assertEqual(image.transparency_get(4, 6), False)
658+
self.assertIs(image.transparency_get(0, 0), True)
659+
self.assertIs(image.transparency_get(4, 6), False)
660660
image.transparency_set(4, 6, True)
661-
self.assertEqual(image.transparency_get(4, 6), True)
661+
self.assertIs(image.transparency_get(4, 6), True)
662662
image.transparency_set(4, 6, False)
663-
self.assertEqual(image.transparency_get(4, 6), False)
663+
self.assertIs(image.transparency_get(4, 6), False)
664664
self.assertRaises(tkinter.TclError, image.transparency_get, -1, 0)
665665
self.assertRaises(tkinter.TclError, image.transparency_get, 16, 0)
666666
self.assertRaises(tkinter.TclError, image.transparency_set, -1, 0, True)

Lib/test/test_tkinter/test_text.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ def test_debug(self):
1818
text = self.text
1919
olddebug = text.debug()
2020
try:
21-
text.debug(0)
22-
self.assertEqual(text.debug(), 0)
23-
text.debug(1)
24-
self.assertEqual(text.debug(), 1)
21+
text.debug(False)
22+
self.assertIs(text.debug(), False)
23+
text.debug(True)
24+
self.assertIs(text.debug(), True)
2525
finally:
2626
text.debug(olddebug)
2727
self.assertEqual(text.debug(), olddebug)

Lib/test/test_ttk/test_widgets.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1685,9 +1685,9 @@ def test_detach_reattach(self):
16851685
self.assertEqual(self.tv.get_children(item_id), ())
16861686

16871687
def test_exists(self):
1688-
self.assertEqual(self.tv.exists('something'), False)
1689-
self.assertEqual(self.tv.exists(''), True)
1690-
self.assertEqual(self.tv.exists({}), False)
1688+
self.assertIs(self.tv.exists('something'), False)
1689+
self.assertIs(self.tv.exists(''), True)
1690+
self.assertIs(self.tv.exists({}), False)
16911691

16921692
# the following will make a tk.call equivalent to
16931693
# tk.call(treeview, "exists") which should result in an error

Lib/tkinter/ttk.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,8 +1483,8 @@ def tag_configure(self, tagname, option=None, **kw):
14831483

14841484

14851485
def tag_has(self, tagname, item=None):
1486-
"""If item is specified, returns 1 or 0 depending on whether the
1487-
specified item has the given tagname. Otherwise, returns a list of
1486+
"""If item is specified, returns True if the specified item has the
1487+
given tagname, False otherwise. Otherwise, returns a list of
14881488
all items which have the specified tag.
14891489
14901490
* Availability: Tk 8.6"""

0 commit comments

Comments
 (0)