[Python-checkins] bpo-41384: Raise TclError in tkinter.OptionMenu (GH-21601)

Miss Islington (bot) webhook-mailer at python.org
Sun Jul 26 22:14:54 EDT 2020


https://github.com/python/cpython/commit/104adedf641dc686069a20ae1a05c821b56e4aa4
commit: 104adedf641dc686069a20ae1a05c821b56e4aa4
branch: 3.8
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2020-07-26T22:14:49-04:00
summary:

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 at udel.edu>
(cherry picked from commit f1d40f941a6483b1d4ea10f1051ace7b426fb8e7)
Co-authored-by: Akuli <akuviljanen17 at gmail.com>

files:
A Misc/NEWS.d/next/Library/2020-07-26-21-18-43.bpo-41384.MlzIgV.rst
M Lib/tkinter/__init__.py
M Lib/tkinter/test/test_tkinter/test_widgets.py

diff --git a/Lib/tkinter/__init__.py b/Lib/tkinter/__init__.py
index 9f0e2e5e94e3a..9d3bf4d49298f 100644
--- a/Lib/tkinter/__init__.py
+++ b/Lib/tkinter/__init__.py
@@ -3963,7 +3963,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:
diff --git a/Lib/tkinter/test/test_tkinter/test_widgets.py b/Lib/tkinter/test/test_tkinter/test_widgets.py
index 16e9d93944c20..721e81369a8d5 100644
--- a/Lib/tkinter/test/test_tkinter/test_widgets.py
+++ b/Lib/tkinter/test/test_tkinter/test_widgets.py
@@ -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):
diff --git a/Misc/NEWS.d/next/Library/2020-07-26-21-18-43.bpo-41384.MlzIgV.rst b/Misc/NEWS.d/next/Library/2020-07-26-21-18-43.bpo-41384.MlzIgV.rst
new file mode 100644
index 0000000000000..d797374a09e6f
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2020-07-26-21-18-43.bpo-41384.MlzIgV.rst
@@ -0,0 +1,2 @@
+Raise TclError instead of TypeError when an unknown option is passed to
+tkinter.OptionMenu.



More information about the Python-checkins mailing list