[Python-3000] range() issues

Guido van Rossum guido at python.org
Wed Apr 30 21:18:20 CEST 2008


I would like to see the following:

- sq_length should return maxsize if the actual value doesn't fit

- if __len__ is implemented in Python, it may return a value >
maxsize, but calling len() will call sq_length, and the sq_length
wrapper that calls __len__ must truncate the value to maxsize

- if a user wants to get the untruncated length of something that
implements __len__ in Python and could return a value > maxsize, they
should call the __len__ method directly (not a very common use case)

--Guido

On Wed, Apr 30, 2008 at 12:14 PM, Marcin 'Qrczak' Kowalczyk
<qrczak at knm.org.pl> wrote:
> Dnia 29-04-2008, wto o godzinie 19:36 -0700, Guido van Rossum pisze:
>
>
>  > Let's also fix __len__() so that it returns sys.{maxint,maxsize} when
>  > the result doesn't fit in a Py_ssize_t.
>
>  Is this official? What should sq_length do when the real size doesn't
>  fit in a Py_ssize_t? It should be documented. Either return maxsize or
>  fail, with OverflowError probably.
>
>  I admit that the only case I have in mind is some virtual sequence
>  analogous to range (wrapped from my language in a Python object).
>
>  --
>    __("<         Marcin Kowalczyk
>    \__/       qrczak at knm.org.pl
>     ^^     http://qrnik.knm.org.pl/~qrczak/
>
>
>
>  _______________________________________________
>  Python-3000 mailing list
>  Python-3000 at python.org
>  http://mail.python.org/mailman/listinfo/python-3000
>  Unsubscribe: http://mail.python.org/mailman/options/python-3000/guido%40python.org
>



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


More information about the Python-3000 mailing list