Skip to content

Commit e7f42be

Browse files
miss-islingtonserhiy-storchakaclaude
authored
[3.13] gh-153422: Assert bool return type in tkinter tests (GH-153429) (GH-153439) (GH-153443)
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 1604c80) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 62eb50d commit e7f42be

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
@@ -1981,7 +1981,7 @@ Base and mixin classes
19811981

19821982
.. method:: winfo_exists()
19831983

1984-
Return ``1`` if the widget exists, ``0`` otherwise.
1984+
Return true if the widget exists, false otherwise.
19851985

19861986
.. method:: winfo_fpixels(number)
19871987

@@ -2020,7 +2020,7 @@ Base and mixin classes
20202020

20212021
.. method:: winfo_ismapped()
20222022

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

20252025
.. method:: winfo_manager()
20262026

@@ -2151,8 +2151,8 @@ Base and mixin classes
21512151

21522152
.. method:: winfo_viewable()
21532153

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

21572157
.. method:: winfo_visual()
21582158

@@ -5526,7 +5526,7 @@ Widget classes
55265526
.. method:: edit_modified(arg=None)
55275527

55285528
If *arg* is omitted, return the current state of the modified flag as
5529-
``0`` or ``1``; the flag is set automatically whenever the text is
5529+
true or false; the flag is set automatically whenever the text is
55305530
inserted or deleted.
55315531
Otherwise set the flag to the boolean *arg*.
55325532

Lib/test/test_tkinter/test_images.py

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

648648
def test_transparency(self):
649649
image = self.create()
650-
self.assertEqual(image.transparency_get(0, 0), True)
651-
self.assertEqual(image.transparency_get(4, 6), False)
650+
self.assertIs(image.transparency_get(0, 0), True)
651+
self.assertIs(image.transparency_get(4, 6), False)
652652
image.transparency_set(4, 6, True)
653-
self.assertEqual(image.transparency_get(4, 6), True)
653+
self.assertIs(image.transparency_get(4, 6), True)
654654
image.transparency_set(4, 6, False)
655-
self.assertEqual(image.transparency_get(4, 6), False)
655+
self.assertIs(image.transparency_get(4, 6), False)
656656
self.assertRaises(tkinter.TclError, image.transparency_get, -1, 0)
657657
self.assertRaises(tkinter.TclError, image.transparency_get, 16, 0)
658658
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
@@ -1650,9 +1650,9 @@ def test_detach_reattach(self):
16501650
self.assertEqual(self.tv.get_children(item_id), ())
16511651

16521652
def test_exists(self):
1653-
self.assertEqual(self.tv.exists('something'), False)
1654-
self.assertEqual(self.tv.exists(''), True)
1655-
self.assertEqual(self.tv.exists({}), False)
1653+
self.assertIs(self.tv.exists('something'), False)
1654+
self.assertIs(self.tv.exists(''), True)
1655+
self.assertIs(self.tv.exists({}), False)
16561656

16571657
# the following will make a tk.call equivalent to
16581658
# 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)