[Python-ideas] (no subject)
Nathaniel Smith
njs at pobox.com
Tue Nov 29 05:38:23 EST 2016
On Tue, Nov 29, 2016 at 1:05 AM, Victor Stinner
<victor.stinner at 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
More information about the Python-ideas
mailing list