X Tutup
The Wayback Machine - https://web.archive.org/web/20240111223233/https://github.com/python/cpython/issues/80825
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve documentation of slice.indices() #80825

Open
pewscorner mannequin opened this issue Apr 16, 2019 · 1 comment
Open

Improve documentation of slice.indices() #80825

pewscorner mannequin opened this issue Apr 16, 2019 · 1 comment
Labels
3.11 bug and security fixes 3.12 bugs and security fixes 3.13 new features, bugs and security fixes docs Documentation in the Doc dir type-feature A feature request or enhancement

Comments

@pewscorner
Copy link
Mannequin

pewscorner mannequin commented Apr 16, 2019

BPO 36644
Nosy @pewscorner

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = None
created_at = <Date 2019-04-16.20:43:52.598>
labels = ['3.8', 'type-feature', '3.7', 'docs']
title = 'Improve documentation of slice.indices()'
updated_at = <Date 2019-04-16.20:43:52.598>
user = 'https://github.com/pewscorner'

bugs.python.org fields:

activity = <Date 2019-04-16.20:43:52.598>
actor = 'pewscorner'
assignee = 'docs@python'
closed = False
closed_date = None
closer = None
components = ['Documentation']
creation = <Date 2019-04-16.20:43:52.598>
creator = 'pewscorner'
dependencies = []
files = []
hgrepos = []
issue_num = 36644
keywords = []
message_count = 1.0
messages = ['340364']
nosy_count = 2.0
nosy_names = ['docs@python', 'pewscorner']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue36644'
versions = ['Python 3.7', 'Python 3.8']

@pewscorner
Copy link
Mannequin Author

pewscorner mannequin commented Apr 16, 2019

The slice class is described in the Built-In Functions document:

https://docs.python.org/3/library/functions.html#slice

... 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:

https://docs.python.org/3/reference/datamodel.html#slice.indices

... but (as the rejected bpo-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:

https://docs.python.org/2.3/whatsnew/section-slices.html

"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.

@pewscorner pewscorner mannequin added 3.7 (EOL) end of life 3.8 only security fixes labels Apr 16, 2019
@pewscorner pewscorner mannequin assigned docspython Apr 16, 2019
@pewscorner pewscorner mannequin added docs Documentation in the Doc dir type-feature A feature request or enhancement labels Apr 16, 2019
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
@iritkatriel iritkatriel added 3.11 bug and security fixes 3.10 only security fixes 3.12 bugs and security fixes and removed 3.8 only security fixes 3.7 (EOL) end of life labels Feb 18, 2023
@erlend-aasland erlend-aasland added 3.13 new features, bugs and security fixes and removed 3.10 only security fixes labels Jan 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.11 bug and security fixes 3.12 bugs and security fixes 3.13 new features, bugs and security fixes docs Documentation in the Doc dir type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants
X Tutup