-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
tkinter.Text.count(index1, index2) returns None not (0,) when index1 equals index2 #97928
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
Comments
There are other issues with
There were no any tests for this method, so all this was unnoticed. Other issues could be solved in compatible way, but the originally reported issue does not have backward compatible solution. Returning I think that the decision of returning 1-tuple for a single count (unless it is zero) was a mistake. The Tk code is different for a single count and multiple code -- a single count is returned as an integer instead of a 1-list. The difference is only disappeared if convert it to string. It would be more convenient for users to get an integer in Python too. But it is a breaking change. Choosing between two breaking changes, returning |
(cherry picked from commit 1b684c8) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
(cherry picked from commit 1b684c8) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
…t.count() Previously they were silently ignored. Now they are errors.
…t() (GH-98436) Previously they were silently ignored. Now they are errors.
…t.count() (pythonGH-98436) Previously they were silently ignored. Now they are errors. (cherry picked from commit e4ec8de) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
…t.count() (pythonGH-98436) Previously they were silently ignored. Now they are errors. (cherry picked from commit e4ec8de) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
It now always returns an integer if one or less counting options are specified. Previously it could return a single count as a 1-tuple, an integer (only if option "update" was specified) or None if no items found. The result is now the same if wantobjects is set to 0.
It now always returns an integer if one or less counting options are specified. Previously it could return a single count as a 1-tuple, an integer (only if option "update" was specified) or None if no items found. The result is now the same if wantobjects is set to 0.
It now always returns an integer if one or less counting options are specified. Previously it could return a single count as a 1-tuple, an integer (only if option "update" was specified) or None if no items found. The result is now the same if wantobjects is set to 0.
Thanks for the fix. |
It was suggested to partially restore the old behavior and add an optional argument return_ints to control the returned value. |
I clicked and read most of that discussion. |
…) by default By default, it preserves an inconsistent behavior of older Python versions: packs the count into a 1-tuple if only one or none options are specified (including 'update'), returns None instead of 0. Except that setting wantobjects to 0 no longer affects the result. Add a new parameter return_ints: specifying return_ints=True makes Text.count() always returning the single count as an integer insteaf of a 1-tuple or None.
…) by default By default, it preserves an inconsistent behavior of older Python versions: packs the count into a 1-tuple if only one or none options are specified (including 'update'), returns None instead of 0. Except that setting wantobjects to 0 no longer affects the result. Add a new parameter return_ints: specifying return_ints=True makes Text.count() always returning the single count as an integer insteaf of a 1-tuple or None.
…efault (GH-115031) By default, it preserves an inconsistent behavior of older Python versions: packs the count into a 1-tuple if only one or none options are specified (including 'update'), returns None instead of 0. Except that setting wantobjects to 0 no longer affects the result. Add a new parameter return_ints: specifying return_ints=True makes Text.count() always returning the single count as an integer instead of a 1-tuple or None.
…-98484) It now always returns an integer if one or less counting options are specified. Previously it could return a single count as a 1-tuple, an integer (only if option "update" was specified) or None if no items found. The result is now the same if wantobjects is set to 0.
…) by default (pythonGH-115031) By default, it preserves an inconsistent behavior of older Python versions: packs the count into a 1-tuple if only one or none options are specified (including 'update'), returns None instead of 0. Except that setting wantobjects to 0 no longer affects the result. Add a new parameter return_ints: specifying return_ints=True makes Text.count() always returning the single count as an integer instead of a 1-tuple or None.
…-98484) It now always returns an integer if one or less counting options are specified. Previously it could return a single count as a 1-tuple, an integer (only if option "update" was specified) or None if no items found. The result is now the same if wantobjects is set to 0.
Surely the Text.count() method should return (0,) in the title code snippet? Following the example of what happens when more than one option is given.
I suppose the text_count method should do so too, but it was a hack of something that did not exist when written.
Tk8.6 documentation says a list of integers is returned.
Sample code below.
Linked PRs
The text was updated successfully, but these errors were encountered: