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.

Title: Improve documentation of slice.indices()
Type: enhancement Stage:
Components: Documentation Versions: Python 3.8, Python 3.7
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: docs@python, pewscorner
Priority: normal Keywords:

Created on 2019-04-16 20:43 by pewscorner, last changed 2022-04-11 14:59 by admin.

Messages (1)
msg340364 - (view) Author: PEW's Corner (pewscorner) * Date: 2019-04-16 20:43
The slice class is described in the Built-In Functions document:

... but that entry fails to mention the indices() method, and states that slice objects "have no other explicit functionality" beyond the start, stop, and step attributes. The entry links only to a glossary item which doesn't provide more info.

However, it turns out that there is another description of slice objects - including the indices() method - in the Data model document:

... but (as the rejected issue 11842 in my opinion correctly argues) this entry is not clear about how to interpret the return values from the indices() method, i.e. that they are appropriate as arguments to range() - not as arguments to a new slice().

So, right now the best documentation of the indices() method is the old Python 2.3 "what's new" documentation of extended slices:

"To simplify implementing sequences that support extended slicing, slice objects now have a method indices(length) which, given the length of a sequence, returns a (start, stop, step) tuple that can be passed directly to range(). indices() handles omitted and out-of-bounds indices in a manner consistent with regular slices (and this innocuous phrase hides a welter of confusing details!)."

I would propose to at least:
* Add a link from the slice class in the Built-In Functions doc to the slice object section of the Data model doc.
* Delete the statement about "no other explicit functionality" in the Built-In Functions doc.
* Mention in the Data model doc that the return values from indices() can be passed to range() to obtain the sequence of indices described by the slice when applied to a sequence object of the specified length, and perhaps make it clear that the indices() values do not in general represent the new start, stop, and step attributes of a truncated slice object.
Date User Action Args
2022-04-11 14:59:14adminsetgithub: 80825
2019-04-16 20:43:52pewscornercreate