Skip to content

Commit

Permalink
bpo-41384: Raise TclError in tkinter.OptionMenu (pythonGH-21601)
Browse files Browse the repository at this point in the history
... 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>
  • Loading branch information
Akuli and terryjreedy committed Jul 27, 2020
1 parent 52bf470 commit f1d40f9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Lib/tkinter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3965,7 +3965,7 @@ def __init__(self, master, variable, value, *values, **kwargs):
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:
Expand Down
4 changes: 4 additions & 0 deletions Lib/tkinter/test/test_tkinter/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Raise TclError instead of TypeError when an unknown option is passed to
tkinter.OptionMenu.

0 comments on commit f1d40f9

Please sign in to comment.