gh-140481: Improve error message when trying to iterate a Tk widget, image or font (GH-140501)

This commit is contained in:
Serhiy Storchaka 2025-10-30 13:11:56 +02:00 committed by GitHub
parent ad0a3f733b
commit 09b1f10ef7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 59 additions and 22 deletions

View file

@ -1,3 +1,4 @@
import collections.abc
import functools
import unittest
import tkinter
@ -508,6 +509,17 @@ def test_embedded_null(self):
widget.selection_range(0, 'end')
self.assertEqual(widget.selection_get(), '\u20ac\0abc\x00def')
def test_iterable_protocol(self):
widget = tkinter.Entry(self.root)
self.assertNotIsSubclass(tkinter.Entry, collections.abc.Iterable)
self.assertNotIsSubclass(tkinter.Entry, collections.abc.Container)
self.assertNotIsInstance(widget, collections.abc.Iterable)
self.assertNotIsInstance(widget, collections.abc.Container)
with self.assertRaisesRegex(TypeError, 'is not iterable'):
iter(widget)
with self.assertRaisesRegex(TypeError, 'is not a container or iterable'):
widget in widget
class WmTest(AbstractTkTest, unittest.TestCase):