[Python-Dev] PEP for adding an sq_index slot so that any object, a or b, can be used in X[a:b] notation

Travis E. Oliphant oliphant.travis at ieee.org
Fri Feb 10 02:35:43 CET 2006

Thomas Wouters wrote:
> On Thu, Feb 09, 2006 at 02:32:47PM -0800, Brett Cannon wrote:
>>Looks good to me.  Only change I might make is mention why __int__
>>doesn't work sooner (such as in the rationale).  Otherwise +1 from me.
> I have a slight reservation about the name. On the one hand it's clear the
> canonical use will be for indexing sequences, and __index__ doesn't look
> enough like __int__ to get people confused on the difference. On the other
> hand, there are other places (in C) that want an actual int, and they could
> use __index__ too. Even more so if a PyArg_Parse* grew a format for 'the
> index-value for this object' ;)

There are other places in Python that check specifically for int objects 
and long integer objects and fail with anything else.  Perhaps all of 
these should aslo call the __index__ slot.

But, then it *should* be renamed to i.e. "__true_int__".  One such place 
is in abstract.c sequence_repeat function.

The patch I submitted, perhaps aggressivele, changed that function to 
call the nb_index slot as well instead of raising an error.

Perhaps the slot should be called nb_true_int?


> On the *other* one hand, I can't think of a good name... but on the other
> other hand, it would be awkward to have to support an old name just because
> the real use wasn't envisioned yet.
> One-time-machine-for-the-shortsighted-quadrumanus-please-ly y'r,s

More information about the Python-Dev mailing list