[Python-ideas] (no subject)

Wes Turner wes.turner at gmail.com
Tue Nov 29 06:20:03 EST 2016


On Tuesday, November 29, 2016, Nathaniel Smith <njs at pobox.com> wrote:

> On Tue, Nov 29, 2016 at 1:05 AM, Victor Stinner
> <victor.stinner at gmail.com <javascript:;>> 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


https://docs.python.org/2/tutorial/datastructures.html#more-on-lists

https://docs.python.org/2/c-api/list.html#c.PyList_SetItem

https://github.com/python/cpython/search?utf8=✓&q=PyList_SetItem

- https://github.com/python/cpython/blob/master/Include/listobject.h
- https://github.com/python/cpython/blob/master/Objects/listobject.c#L208
- https://hg.python.org/cpython/file/tip/Objects/listobject.c#l208

https://docs.python.org/3/library/collections.abc.html#collections-abstract-base-classes

- list (typeshed: List)
- Sequence
- MutableSequence
-

It would be great if these continue to match:
https://www.google.com/search?q=IndexError%3A+list+index+out+of+range



>
> -n
>
> --
> Nathaniel J. Smith -- https://vorpus.org
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org <javascript:;>
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20161129/f5511544/attachment.html>


More information about the Python-ideas mailing list