From 2a113a6ce22ca77f8bcc9502fac24e277b41b8a0 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Fri, 14 Oct 2022 17:33:09 +0300 Subject: [PATCH] gh-97928: Fix handling options starting with "-" in tkinter.Text.count() Previously they were silently ignored. Now they are errors. --- Lib/test/test_tkinter/test_text.py | 4 +--- Lib/tkinter/__init__.py | 2 +- .../Library/2022-10-19-09-29-12.gh-issue-97928.xj3im7.rst | 2 ++ 3 files changed, 4 insertions(+), 4 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2022-10-19-09-29-12.gh-issue-97928.xj3im7.rst diff --git a/Lib/test/test_tkinter/test_text.py b/Lib/test/test_tkinter/test_text.py index b8dfde62070bbd..328e4256ce0711 100644 --- a/Lib/test/test_tkinter/test_text.py +++ b/Lib/test/test_tkinter/test_text.py @@ -76,9 +76,7 @@ def test_count(self): self.assertEqual(text.count('1.0', 'end'), (124,) # 'indices' by default if self.wantobjects else ('124',)) self.assertRaises(tkinter.TclError, text.count, '1.0', 'end', 'spam') - # '-lines' is ignored, 'indices' is used by default - self.assertEqual(text.count('1.0', 'end', '-lines'), (124,) - if self.wantobjects else ('124',)) + self.assertRaises(tkinter.TclError, text.count, '1.0', 'end', '-lines') self.assertIsInstance(text.count('1.3', '1.5', 'ypixels'), tuple) self.assertIsInstance(text.count('1.3', '1.5', 'update', 'ypixels'), int diff --git a/Lib/tkinter/__init__.py b/Lib/tkinter/__init__.py index 356446911e0abc..a8e7bf490ad463 100644 --- a/Lib/tkinter/__init__.py +++ b/Lib/tkinter/__init__.py @@ -3648,7 +3648,7 @@ def count(self, index1, index2, *args): # new in Tk 8.5 "lines", "xpixels" and "ypixels". There is an additional possible option "update", which if given then all subsequent options ensure that any possible out of date information is recalculated.""" - args = ['-%s' % arg for arg in args if not arg.startswith('-')] + args = ['-%s' % arg for arg in args] args += [index1, index2] res = self.tk.call(self._w, 'count', *args) or None if res is not None and len(args) <= 3: diff --git a/Misc/NEWS.d/next/Library/2022-10-19-09-29-12.gh-issue-97928.xj3im7.rst b/Misc/NEWS.d/next/Library/2022-10-19-09-29-12.gh-issue-97928.xj3im7.rst new file mode 100644 index 00000000000000..cf33db7548f69f --- /dev/null +++ b/Misc/NEWS.d/next/Library/2022-10-19-09-29-12.gh-issue-97928.xj3im7.rst @@ -0,0 +1,2 @@ +:meth:`tkinter.Text.count` raises now an exception for options starting with +"-" instead of silently ignoring them.