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

Guido van Rossum guido at python.org
Mon Feb 13 22:30:26 CET 2006


On 2/13/06, Jim Jewett <jimjjewett at gmail.com> wrote:

Travis wrote:

> The patch adds a new API function int PyObjectAsIndex(obj) How did you decide between int and long? Why not ssizet?

It should be the same type used everywhere for indexing. In the svn HEAD that's int. Once PEP 353 lands it should be ssize_t. I've made Travis aware of this issue already.

Also, if index is being added as a builtin, should the failure result be changed?

I don't like to add a built-in index() at this point; mostly because of Occam's razor (we haven't found a need).

I'm thinking that this may become a replacement for isinstance(val, (int, long)).

But only if it's okay if values > sys.maxint (or some other constant indicating the limit of ssize_t) are not required to be supported.

If so, it might be nice not to raise errors, or at least to raise a more specific subclass. (Catching a TypeError and then checking the message string ... does not seem clean.)

I'm not sure what you mean. How could index(x) ever replace isinstance(x, (int, long)) without raising an exception? Surely index("abc") should raise an exception.

-- --Guido van Rossum (home page: http://www.python.org/~guido/)



More information about the Python-Dev mailing list