[Python-Dev] Bad interaction of __index__ and sequence repeat
Greg Ewing
greg.ewing at canterbury.ac.nz
Sat Jul 29 05:09:46 CEST 2006
Tim Peters wrote:
> So, e.g., plain a[i] shouldn't use __index__ either if i is already
> int or long. I don't see any justification for invoking nb_index in
> sequence_repeat(), although if someone thinks it should, then as for
> plain indexing it certainly shouldn't invoke nb_index if the incoming
> count is an int or long to begin with.
Hmmm. So that means anything accepting an integer index
needs to do its own range checking anyway. So having
__index__ do clipping is at best unnecessary and at worst
counterproductive, since it could suppress an overflow
or range exception that *should* be produced by the code
using the index, and would be if it got the equivalent
index value as an int or long directly.
--
Greg
More information about the Python-Dev
mailing list