gh-97928: Fix handling options starting with "-" in tkinter.Text.count() (GH-98436)

Previously they were silently ignored. Now they are errors.
This commit is contained in:
Serhiy Storchaka 2022-10-19 12:30:14 +03:00 committed by GitHub
parent 1b684c8f5f
commit e4ec8de6fa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 4 deletions

View file

@ -76,9 +76,7 @@ class TextTest(AbstractTkTest, unittest.TestCase):
self.assertEqual(text.count('1.0', 'end'), (124,) # 'indices' by default self.assertEqual(text.count('1.0', 'end'), (124,) # 'indices' by default
if self.wantobjects else ('124',)) if self.wantobjects else ('124',))
self.assertRaises(tkinter.TclError, text.count, '1.0', 'end', 'spam') self.assertRaises(tkinter.TclError, text.count, '1.0', 'end', 'spam')
# '-lines' is ignored, 'indices' is used by default self.assertRaises(tkinter.TclError, text.count, '1.0', 'end', '-lines')
self.assertEqual(text.count('1.0', 'end', '-lines'), (124,)
if self.wantobjects else ('124',))
self.assertIsInstance(text.count('1.3', '1.5', 'ypixels'), tuple) self.assertIsInstance(text.count('1.3', '1.5', 'ypixels'), tuple)
self.assertIsInstance(text.count('1.3', '1.5', 'update', 'ypixels'), int self.assertIsInstance(text.count('1.3', '1.5', 'update', 'ypixels'), int

View file

@ -3648,7 +3648,7 @@ class Text(Widget, XView, YView):
"lines", "xpixels" and "ypixels". There is an additional possible "lines", "xpixels" and "ypixels". There is an additional possible
option "update", which if given then all subsequent options ensure option "update", which if given then all subsequent options ensure
that any possible out of date information is recalculated.""" 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] args += [index1, index2]
res = self.tk.call(self._w, 'count', *args) or None res = self.tk.call(self._w, 'count', *args) or None
if res is not None and len(args) <= 3: if res is not None and len(args) <= 3:

View file

@ -0,0 +1,2 @@
:meth:`tkinter.Text.count` raises now an exception for options starting with
"-" instead of silently ignoring them.