]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-41384: Raise TclError in tkinter.OptionMenu (GH-21601)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 27 Jul 2020 02:14:49 +0000 (19:14 -0700)
committerGitHub <noreply@github.com>
Mon, 27 Jul 2020 02:14:49 +0000 (22:14 -0400)
... 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 f1d40f941a6483b1d4ea10f1051ace7b426fb8e7)
Co-authored-by: Akuli <akuviljanen17@gmail.com>
Lib/tkinter/__init__.py
Lib/tkinter/test/test_tkinter/test_widgets.py
Misc/NEWS.d/next/Library/2020-07-26-21-18-43.bpo-41384.MlzIgV.rst [new file with mode: 0644]

index 9f0e2e5e94e3af53a66f0790a9f5b167ee2d6937..9d3bf4d49298f90afdb86bee4e51607f819594a3 100644 (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:
index 16e9d93944c205db067f9a80704130149e925cb2..721e81369a8d5b726368f68dad7cfb68b5a5a81f 100644 (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):
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 (file)
index 0000000..d797374
--- /dev/null
@@ -0,0 +1,2 @@
+Raise TclError instead of TypeError when an unknown option is passed to
+tkinter.OptionMenu.