Skip to content

[3.10] gh-97928: Fix handling options starting with "-" in tkinter.Text.count() (GH-98436) #98439

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Lib/tkinter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3621,7 +3621,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:
Expand Down
4 changes: 1 addition & 3 deletions Lib/tkinter/test/test_tkinter/test_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
:meth:`tkinter.Text.count` raises now an exception for options starting with
"-" instead of silently ignoring them.