[Python-3000] find -> index patch

Josiah Carlson jcarlson at uci.edu
Thu Aug 24 01:39:03 CEST 2006

"Hasan Diwan" <hasan.diwan at gmail.com> wrote:
> On 23/08/06, Josiah Carlson <jcarlson at uci.edu> wrote:
> >
> > ...that looks to have been done by a script, it has inconsistant style
> > compared to the code it replaces, etc.
> >
> I made the minimal change that implements the functionality suggested, in
> terms of find/rfind, they return -1. The least painful way to replace it
> with index is:
> try:
>     i=str.index(foo)
> except ValueError:
>     i = -1
> As for the plain except clauses, that was just laziness on my part. It's not
> meant to be stylistically consistent or beautiful, rather it is meant to be
> functional and as a starting point. Feel free to change/rewrite the patch.
> The GENERAL CASE, i.e. one that is applicable throughout the code is the
> try/except clauses shown above.

If find is to be replaced, it should be replaced with something that
isn't as cumbersome to use as index, and shouldn't be done in a bulk
replacement attempt; as you have also shown that doing such can lead to
unintended new bugs and the possible perpetuation of old bugs.

When Raymond Hettinger did the same thing to replace some examples of
find with partition, in my first pass over his proposed patch, I
also discovered a handful of new and perpetuated bugs, which was in a
similar skimming of the patches.

I'm also not going to fix the patch because I don't believe that
replacing find with index is the correct course of action, for the few
reasons I've laid out in the current and previous messages on the topic.

 - Josiah

More information about the Python-3000 mailing list