This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eryksun
Recipients Elizacat, eryksun
Date 2016-07-11.04:24:42
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1468211082.7.0.314580047061.issue27479@psf.upfronthosting.co.za>
In-reply-to
Content
This is documented behavior for the built-in sequence types [1], and it's also mentioned in the tutorial [2].

The indices() method of a slice object shows the resolved bounds for given sequence length:

    >>> slice(-1000, 1000, 1).indices(4)
    (0, 4, 1)
    >>> slice(None, None, 1).indices(4)
    (0, 4, 1)

    >>> slice(1000, -1000, -1).indices(4)
    (3, -1, -1)
    >>> slice(None, None, -1).indices(4)
    (3, -1, -1)

The rules apply the same to list, tuple, and range sequences:

    >>> [1, 2, 3, 4][-1000:1000]
    [1, 2, 3, 4]
    >>> (1, 2, 3, 4)[-1000:1]
    (1,)
    >>> range(0)[-100:100]
    range(0, 0)

[1]: https://docs.python.org/3/library/stdtypes.html#common-sequence-operations
[2]: https://docs.python.org/3/tutorial/introduction.html#strings
History
Date User Action Args
2016-07-11 04:24:42eryksunsetrecipients: + eryksun, Elizacat
2016-07-11 04:24:42eryksunsetmessageid: <1468211082.7.0.314580047061.issue27479@psf.upfronthosting.co.za>
2016-07-11 04:24:42eryksunlinkissue27479 messages
2016-07-11 04:24:42eryksuncreate