![](https://secure.gravatar.com/avatar/97c543aca1ac7bbcfb5279d0300c8330.jpg?s=120&d=mm&r=g)
On Tue, Nov 29, 2016 at 1:05 AM, Victor Stinner <victor.stinner@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