[issue44166] Make IndexError messages for list more informative

Serhiy Storchaka report at bugs.python.org
Tue May 18 05:10:08 EDT 2021


Serhiy Storchaka <storchaka+cpython at gmail.com> added the comment:

The problem is that such exceptions are often used with the EAFP style. For example:

        while stop is None or i < stop:
            try:
                v = self[i]
                if v is value or v == value:
                    return i
            except IndexError:
                break
            i += 1

You caught IndexError and do something, but do not use the error message. Formatting error message takes a time. I am sure that error messages of a wast majority of IndexError exceptions are not used, just the type of the raised exception matters.

----------
nosy: +serhiy.storchaka

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44166>
_______________________________________


More information about the Python-bugs-list mailing list