Skip to content

Commit e4ec8de

Browse files
gh-97928: Fix handling options starting with "-" in tkinter.Text.count() (GH-98436)
Previously they were silently ignored. Now they are errors.
1 parent 1b684c8 commit e4ec8de

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

Lib/test/test_tkinter/test_text.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,7 @@ def test_count(self):
7676
self.assertEqual(text.count('1.0', 'end'), (124,) # 'indices' by default
7777
if self.wantobjects else ('124',))
7878
self.assertRaises(tkinter.TclError, text.count, '1.0', 'end', 'spam')
79-
# '-lines' is ignored, 'indices' is used by default
80-
self.assertEqual(text.count('1.0', 'end', '-lines'), (124,)
81-
if self.wantobjects else ('124',))
79+
self.assertRaises(tkinter.TclError, text.count, '1.0', 'end', '-lines')
8280

8381
self.assertIsInstance(text.count('1.3', '1.5', 'ypixels'), tuple)
8482
self.assertIsInstance(text.count('1.3', '1.5', 'update', 'ypixels'), int

Lib/tkinter/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3648,7 +3648,7 @@ def count(self, index1, index2, *args): # new in Tk 8.5
36483648
"lines", "xpixels" and "ypixels". There is an additional possible
36493649
option "update", which if given then all subsequent options ensure
36503650
that any possible out of date information is recalculated."""
3651-
args = ['-%s' % arg for arg in args if not arg.startswith('-')]
3651+
args = ['-%s' % arg for arg in args]
36523652
args += [index1, index2]
36533653
res = self.tk.call(self._w, 'count', *args) or None
36543654
if res is not None and len(args) <= 3:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
:meth:`tkinter.Text.count` raises now an exception for options starting with
2+
"-" instead of silently ignoring them.

0 commit comments

Comments
 (0)