Skip to content

Commit eee8b99

Browse files
gh-97928: Fix handling options starting with "-" in tkinter.Text.count() (GH-98436)
Previously they were silently ignored. Now they are errors. (cherry picked from commit e4ec8de) Co-authored-by: Serhiy Storchaka <[email protected]>
1 parent d0ed05c commit eee8b99

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

Lib/tkinter/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3621,7 +3621,7 @@ def count(self, index1, index2, *args): # new in Tk 8.5
36213621
"lines", "xpixels" and "ypixels". There is an additional possible
36223622
option "update", which if given then all subsequent options ensure
36233623
that any possible out of date information is recalculated."""
3624-
args = ['-%s' % arg for arg in args if not arg.startswith('-')]
3624+
args = ['-%s' % arg for arg in args]
36253625
args += [index1, index2]
36263626
res = self.tk.call(self._w, 'count', *args) or None
36273627
if res is not None and len(args) <= 3:

Lib/tkinter/test/test_tkinter/test_text.py

Lines changed: 1 addition & 3 deletions
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
Lines changed: 2 additions & 0 deletions
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)