]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-103685: Fix tkinter.Menu.index() for Tk 8.7 (#103686)
authorChristopher Chavez <chrischavez@gmx.us>
Mon, 24 Apr 2023 01:31:44 +0000 (20:31 -0500)
committerGitHub <noreply@github.com>
Mon, 24 Apr 2023 01:31:44 +0000 (21:31 -0400)
---------

Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Lib/test/test_tkinter/test_widgets.py
Lib/tkinter/__init__.py
Misc/NEWS.d/next/Library/2023-04-24-00-34-23.gh-issue-103685.U14jBM.rst [new file with mode: 0644]

index 64c9472706549bb045771ee52bbe39cf745d9df2..ba4ef49078c5a7510ff55df8e3524be4f1aa597e 100644 (file)
@@ -1377,6 +1377,11 @@ class MenuTest(AbstractWidgetTest, unittest.TestCase):
     def create(self, **kwargs):
         return tkinter.Menu(self.root, **kwargs)
 
+    def test_indexcommand_none(self):
+        widget = self.create()
+        i = widget.index('none')
+        self.assertIsNone(i)
+
     def test_configure_postcommand(self):
         widget = self.create()
         self.checkCommandParam(widget, 'postcommand')
index 479daf0e5abfc38910ca241ca4884e0bc8d7c8e7..bf0b3b92155938c1ea86be62866c0980dd82c17b 100644 (file)
@@ -3430,8 +3430,7 @@ class Menu(Widget):
     def index(self, index):
         """Return the index of a menu item identified by INDEX."""
         i = self.tk.call(self._w, 'index', index)
-        if i == 'none': return None
-        return self.tk.getint(i)
+        return None if i in ('', 'none') else self.tk.getint(i)  # GH-103685.
 
     def invoke(self, index):
         """Invoke a menu item identified by INDEX and execute
diff --git a/Misc/NEWS.d/next/Library/2023-04-24-00-34-23.gh-issue-103685.U14jBM.rst b/Misc/NEWS.d/next/Library/2023-04-24-00-34-23.gh-issue-103685.U14jBM.rst
new file mode 100644 (file)
index 0000000..31df047
--- /dev/null
@@ -0,0 +1 @@
+Prepare :meth:`tkinter.Menu.index` for Tk 8.7 so that it does not raise ``TclError: expected integer but got ""`` when it should return ``None``.