From 65e8708edef51047717c21ad27b0a5a89210fb66 Mon Sep 17 00:00:00 2001 From: Christopher Chavez Date: Sat, 22 Apr 2023 11:13:54 -0500 Subject: [PATCH 1/6] gh-103685: Fix tkinter.Menu.index() for Tk 8.7 --- Lib/tkinter/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/tkinter/__init__.py b/Lib/tkinter/__init__.py index 479daf0e5abfc3..ac740e9a8e05f3 100644 --- a/Lib/tkinter/__init__.py +++ b/Lib/tkinter/__init__.py @@ -3430,7 +3430,7 @@ def entryconfigure(self, index, cnf=None, **kw): 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 + if i in ('', 'none'): return None return self.tk.getint(i) def invoke(self, index): From a293a6b98485605233661fd246dcb09a95a69359 Mon Sep 17 00:00:00 2001 From: Christopher Chavez Date: Sat, 22 Apr 2023 16:39:29 -0500 Subject: [PATCH 2/6] Update Lib/tkinter/__init__.py Co-authored-by: Terry Jan Reedy --- Lib/tkinter/__init__.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Lib/tkinter/__init__.py b/Lib/tkinter/__init__.py index ac740e9a8e05f3..bf0b3b92155938 100644 --- a/Lib/tkinter/__init__.py +++ b/Lib/tkinter/__init__.py @@ -3430,8 +3430,7 @@ def entryconfigure(self, index, cnf=None, **kw): def index(self, index): """Return the index of a menu item identified by INDEX.""" i = self.tk.call(self._w, 'index', index) - if i in ('', '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 From 1cc85073aad05841d39b539cf4856cd55545eb64 Mon Sep 17 00:00:00 2001 From: Christopher Chavez Date: Sun, 23 Apr 2023 03:22:38 -0500 Subject: [PATCH 3/6] Add a test for tkinter.Menu.index('none') --- Lib/test/test_tkinter/test_widgets.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Lib/test/test_tkinter/test_widgets.py b/Lib/test/test_tkinter/test_widgets.py index 64c9472706549b..ba4ef49078c5a7 100644 --- a/Lib/test/test_tkinter/test_widgets.py +++ b/Lib/test/test_tkinter/test_widgets.py @@ -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') From 4fc68f577e6bfa22494d20126cb2819a7e986f84 Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Sun, 23 Apr 2023 16:44:13 -0400 Subject: [PATCH 4/6] Test index(''), which currently fails. --- Lib/test/test_tkinter/test_widgets.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Lib/test/test_tkinter/test_widgets.py b/Lib/test/test_tkinter/test_widgets.py index ba4ef49078c5a7..39f6b60fe2fd67 100644 --- a/Lib/test/test_tkinter/test_widgets.py +++ b/Lib/test/test_tkinter/test_widgets.py @@ -1381,6 +1381,8 @@ def test_indexcommand_none(self): widget = self.create() i = widget.index('none') self.assertIsNone(i) + i = widget.index('') + self.assertIsNone(i) def test_configure_postcommand(self): widget = self.create() From bbc4c48f4367fede5b1216cd52f1bbd444f05f98 Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Sun, 23 Apr 2023 19:04:15 -0400 Subject: [PATCH 5/6] Remove bad test --- Lib/test/test_tkinter/test_widgets.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/Lib/test/test_tkinter/test_widgets.py b/Lib/test/test_tkinter/test_widgets.py index 39f6b60fe2fd67..ba4ef49078c5a7 100644 --- a/Lib/test/test_tkinter/test_widgets.py +++ b/Lib/test/test_tkinter/test_widgets.py @@ -1381,8 +1381,6 @@ def test_indexcommand_none(self): widget = self.create() i = widget.index('none') self.assertIsNone(i) - i = widget.index('') - self.assertIsNone(i) def test_configure_postcommand(self): widget = self.create() From 55629ca5824753bf4dca900d88eba041bb99e62b Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Mon, 24 Apr 2023 00:34:24 +0000 Subject: [PATCH 6/6] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2023-04-24-00-34-23.gh-issue-103685.U14jBM.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2023-04-24-00-34-23.gh-issue-103685.U14jBM.rst 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 index 00000000000000..31df04790721a8 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-04-24-00-34-23.gh-issue-103685.U14jBM.rst @@ -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``.