Bug in string.find; was: Re: Proposed PEP: New style indexing,was Re: Bug in slice type
tjreedy at udel.edu
Tue Aug 30 07:22:31 CEST 2005
"Steve Holden" <steve at holdenweb.com> wrote in message
news:devuln$bro$1 at sea.gmane.org...
> Antoon Pardon wrote:
>> So what happens if you have a module that is collecting string-index
>> pair, colleted from various other parts. In one part you
>> want to select the last letter, so you pythonically choose -1 as
>> index. In an other part you get a result of find and are happy
>> with -1 as an indictation for an invalid index. Then these
>> data meet.
> That's when debugging has to start. Mixing data of such types is
> somewhat inadvisable, don't you agree?
> I suppose I can't deny that people do things like that, myself included,
> but mixing data sets where -1 is variously an error flag and a valid
> index is only going to lead to trouble when the combined data is used.
The fact that the -1 return *has* lead to bugs in actual code is the
primary reason Guido has currently decided that find and rfind should go.
A careful review of current usages in the standard library revealed at
least a couple bugs even there.
Terry J. Reedy
More information about the Python-list