bpo-41384: Raise TclError in tkinter.OptionMenu (GH-21601)

... when an unknown option is passed.  TypeError was being raised because a 2to3 fix was missing.

Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
(cherry picked from commit f1d40f941a)
Co-authored-by: Akuli <akuviljanen17@gmail.com>
This commit is contained in:
Miss Islington (bot) 2020-07-26 19:14:49 -07:00 committed by GitHub
parent 33cebe0b9a
commit 104adedf64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 1 deletions

View File

@ -3963,7 +3963,7 @@ class OptionMenu(Menubutton):
if 'command' in kwargs:
del kwargs['command']
if kwargs:
raise TclError('unknown option -'+kwargs.keys()[0])
raise TclError('unknown option -'+next(iter(kwargs)))
menu.add_command(label=value,
command=_setit(variable, value, callback))
for v in values:

View File

@ -307,6 +307,10 @@ class OptionMenuTest(MenubuttonTest, unittest.TestCase):
def create(self, default='b', values=('a', 'b', 'c'), **kwargs):
return tkinter.OptionMenu(self.root, None, default, *values, **kwargs)
def test_bad_kwarg(self):
with self.assertRaisesRegex(TclError, r"^unknown option -image$"):
tkinter.OptionMenu(self.root, None, 'b', image='')
@add_standard_options(IntegerSizeTests, StandardOptionsTests)
class EntryTest(AbstractWidgetTest, unittest.TestCase):

View File

@ -0,0 +1,2 @@
Raise TclError instead of TypeError when an unknown option is passed to
tkinter.OptionMenu.