On Tue, Nov 29, 2016 at 1:05 AM, Victor Stinner
<victor.stin...@gmail.com> wrote:
> Hi,
>
> Python is optimized for performance. Formatting an error message has a
> cost on performances.

Sure, but we have to look at this on a case-by-case basis. Is there
really important code out there that's generating NameErrors or
SyntaxErrors in an inner loop? That seems unlikely to me.

Even IndexError I'm a bit skeptical about. I can believe that there's
code that intentionally generates and then catches IndexError, but
AttributeError in my experience is much more performance-sensitive
than IndexError, because every failed hasattr call allocates an
AttributeError and hasattr is commonly used for feature checks. Yet
AttributeError has a much more informative (= expensive) message than
IndexError:

In [1]: object().a
AttributeError: 'object' object has no attribute 'a'

In [2]: list()[0]
IndexError: list index out of range

-n

-- 
Nathaniel J. Smith -- https://vorpus.org
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to