]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-97928: Fix handling options starting with "-" in tkinter.Text.count() (GH-98436)
authorSerhiy Storchaka <storchaka@gmail.com>
Wed, 19 Oct 2022 09:30:14 +0000 (12:30 +0300)
committerGitHub <noreply@github.com>
Wed, 19 Oct 2022 09:30:14 +0000 (12:30 +0300)
Previously they were silently ignored. Now they are errors.

Lib/test/test_tkinter/test_text.py
Lib/tkinter/__init__.py
Misc/NEWS.d/next/Library/2022-10-19-09-29-12.gh-issue-97928.xj3im7.rst [new file with mode: 0644]

index b8dfde62070bbd8741abee967df49c82adcd8134..328e4256ce0711eb9937e1f21eac0e8d3dc70b93 100644 (file)
@@ -76,9 +76,7 @@ class TextTest(AbstractTkTest, unittest.TestCase):
         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
index 356446911e0abc3ba5dac10272b626e35f03c896..a8e7bf490ad46362f2e152f573fa786d8f379847 100644 (file)
@@ -3648,7 +3648,7 @@ class Text(Widget, XView, YView):
         "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 (file)
index 0000000..cf33db7
--- /dev/null
@@ -0,0 +1,2 @@
+:meth:`tkinter.Text.count` raises now an exception for options starting with
+"-" instead of silently ignoring them.