Why not just show the out-of-range index?

John Machin sjmachin at lexicon.net
Mon Dec 4 00:28:13 EST 2006


Jean-Paul Calderone wrote:
> On 3 Dec 2006 17:23:49 -0800, Russ <uymqlp502 at sneakemail.com> wrote:
> >
> >> Rather, they (like I) will encourage to OP to submit a patch that fixes the problem.
> >
> >Now, that would be rather silly. I would have to familiarize myself
> >with the code for the Python interpreter, then send a patch to the
> >maintainers (and hope they notice it in their inboxes), while the
> >maintainers themselves could probably "fix" the problem in two minutes
> >flat. No thanks!
>
> And I have some laundry that I would like you to do for me.  Let me know
> when a convenient time for you to pick it up would be.
>
> Jean-Paul

Perhaps a better analogy is that the OP has observed (correctly IMHO)
that the robes of *all* Pythonistas, including those not yet born and
those not yet converted from heathen languages, could be whiter than
what they are. There are others whose capability to implement an
enhancement is likely to be much greater than his.

IOW, apart from being somewhat impolite, he may:
* not be able to write C
* not understand that apart from listobject.c, he might have to patch
(OTTOMH) stringobject.c, tupleobject.c, arraymodule.c and who knows
what else [see below]
* not come up with a good message

Would the following be acceptable, BTW?

| >>> [4, 5, 6][10]
| IndexError: list index 10 out of range(3)
| >>> [4, 5, 6][-4]
| IndexError: list index -4 out of range(3)

or would something like
 ... out of range; len is 3
be better?

Footnote: Based on 2.4.3 source, quite a few files, many with multiple
lines to patch:

C:\Python_source\Python-2.4.3\Objects>grep -n "index out of range" *.c
File bufferobject.c:
406                     PyErr_SetString(PyExc_IndexError, "buffer index
out of range");
450                                     "buffer assignment index out of
range");
File listobject.c:
144                                     "list index out of range");
165                                     "list assignment index out of
range");
389                                     "list index out of range");
693                                     "list assignment index out of
range");
881                     PyErr_SetString(PyExc_IndexError, "pop index
out of range");
File rangeobject.c:
143                                     "xrange object index out of
range");
File stringobject.c:
1041                    PyErr_SetString(PyExc_IndexError, "string index
out of range");
File structseq.c:
62                      PyErr_SetString(PyExc_IndexError, "tuple index
out of range");
File tupleobject.c:
104                     PyErr_SetString(PyExc_IndexError, "tuple index
out of range");
123                                     "tuple assignment index out of
range");
310                     PyErr_SetString(PyExc_IndexError, "tuple index
out of range");
File unicodeobject.c:
5241            PyErr_SetString(PyExc_IndexError, "string index out of
range");

C:\Python_source\Python-2.4.3\Modules>grep -n "index out of range" *.c
File arraymodule.c:
599                     PyErr_SetString(PyExc_IndexError, "array index
out of range");
767                                      "array assignment index out of
range");
997                     PyErr_SetString(PyExc_IndexError, "pop index
out of range");
File collectionsmodule.c:
399                                     "deque index out of range");
461                                     "deque index out of range");
File mmapmodule.c:
648                     PyErr_SetString(PyExc_IndexError, "mmap index
out of range");
736                     PyErr_SetString(PyExc_IndexError, "mmap index
out of range");
File regexmodule.c:
181                     PyErr_SetString(RegexError, "group() index out
of range");
File _heapqmodule.c:
19                      PyErr_SetString(PyExc_IndexError, "index out of
range");
58                      PyErr_SetString(PyExc_IndexError, "index out of
range");
136                     PyErr_SetString(PyExc_IndexError, "index out of
range");
173                     PyErr_SetString(PyExc_IndexError, "index out of
range");
310                     PyErr_SetString(PyExc_IndexError, "index out of
range");
349                     PyErr_SetString(PyExc_IndexError, "index out of
range");

Cheers,
John




More information about the Python-list mailing list