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

Nick Coghlan ncoghlan at gmail.com
Fri Feb 10 13:45:44 CET 2006


Guido van Rossum wrote:
>> But, then it *should* be renamed to i.e. "__true_int__".  One such place
>> is in abstract.c sequence_repeat function.
> 
> I don't like __true_int__ very much. Personally, I'm fine with calling
> it __index__ after the most common operation. (Well, I would be since
> I think I came up with the name in the first place. :-) Since naming
> is always so subjective *and* important, I'll wait a few days, but if
> nobody suggests something better then we should just go with
> __index__.

An alternative would be to call it "__discrete__", as that is the key 
characteristic of an indexing type - it consists of a sequence of discrete 
values that can be isomorphically mapped to the integers. Numbers conceptually 
representing continuously variable quantities (such as floats and decimals) 
are the ones that really shouldn't define this method.

I wouldn't mind __index__ though, as even though some of the use cases won't 
be strictly using the result as an index, the shared characteristic of being 
isomorphic to the integers should be sufficient to allow the term to make some 
sort of sense.

This would hardly be the first case where names of operators are overloaded 
using imprecise terminology, after all. 'or', 'and', 'sub' and 'xor' aren't 
the right terms for set union, intersection, difference and disjunction, but 
they're close enough conceptually that the names still have meaning. Ditto for 
'mul' and 'add' meaning repetition and concatenation for sequences (no comment 
on 'mod' and string formatting though. . .)

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://www.boredomandlaziness.org


More information about the Python-Dev mailing list