Message 79459 - Python tracker (original) (raw)
Split this from issue 1581476 as suggested by Guilherme Polo (gpolo).
Matthias: your issue about the pattern should be placed in a different issue.
Quote of my original report: (This is about the search function of the Text class in Tkinter. An IndexError is raised when pattern == '') ...
In addition I get an IndexError, if I delete the last character of the search string. Does Tk allow calling search with an empty pattern?
Tkinter could handle this (with a correct result) with the following change in Tkinter.py / Text.search():
if pattern[0] == '-': args.append('--') -> if pattern and pattern[0] == '-': args.append('--')
A further remark from Guilherme Polo (gpolo):
For the suggestion about fixing the search method regarding the pattern: the fix is almost fine, but we need to disallow None as a pattern.
I do not understand that remark. Is it to avoid the TclError? Or because the exception changes (IndexError -> TclError)? What do you want to do when pattern == None? Raise ValueError or IndexError (as before)?
Appended slightly simplified demo program from issue 1581476 and a patch against trunk r68445.
Cheers, Matthias Kievernagel mkiever/at/web/dot/de