That is not what slice.indices does. Per help(slice.indices) - "S.indices(len) -> (start, stop, stride)
"Assuming a sequence of length len, calculate the start and stop indices, and the stride length of the extended slice described by S. Out of bounds indices are clipped in a manner consistent with handling of normal slices. Essentially, it returns (S.start, len, S.step), with start and stop adjusted to prevent out-of-bounds indices. On Tue, Nov 13, 2018, 12:50 PM Vladimir Filipović <hemf...@gmail.com wrote: > On Mon, Nov 12, 2018 at 4:43 PM Nicholas Harrison > <nicholasharrison...@gmail.com> wrote: > > Only when this is called (implicitly or explicitly) do checks for valid > objects and bounds occur. From my experience using slices, this is how they > work in that context too. > > On reconsideration, I've found one more argument in favour of (at > least this aspect of?) the proposal: the slice.indices method, which > takes a sequence's length and returns an iterable (range) of all > indices of such a sequence that would be "selected" by the slice. Not > sure if it's supposed to be documented. > > So there is definitely precedent for "though slices in general are > primarily a syntactic construct and new container-like classes can > choose any semantics for indexing with them, the semantics > specifically in the context of sequences have a bit of a privileged > place in the language with concrete expectations, including strictly > integer (or None) attributes". > _______________________________________________ > Python-ideas mailing list > Python-ideas@python.org > https://mail.python.org/mailman/listinfo/python-ideas > Code of Conduct: http://python.org/psf/codeofconduct/ >
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/