-
-
Notifications
You must be signed in to change notification settings - Fork 33.9k
gh-143420: Clarify sequence behavior for slice indexes #143422
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
base: main
Are you sure you want to change the base?
Conversation
This explain what happens when for negative start or stop arguments of big magnitude. Also reference sequence term in the :mod:`array` docs.
|
CC @hugovk, per experts index (see issue thread on proposal to remove redundant methods from array docs) |
|
|
||
| This module defines an object type which can compactly represent an array of | ||
| basic values: characters, integers, floating-point numbers. Arrays are sequence | ||
| basic values: characters, integers, floating-point numbers. Arrays are :term:`sequence` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe directly say "mutable sequence" types?
| ``len(s)``. If *i* or *j* is less than ``-len(s)``, use ``0``. | ||
| If *i* is omitted or ``None``, use ``0``. If *j* is omitted or | ||
| ``None``, use ``len(s)``. If *i* is greater than or equal to *j*, the slice is |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could compress this as:
If *i* or *j* is greater than ``len(s)`` (respectively, ``-len(s)``), use ``len(s)`` (respectively, ``0``). If *i* (respectively, *j*) is
omitted or ``None``, use ``0`` (respectively ``len(s)``).However, for readers not familiar with the If X (resp. X'), then Y (resp. Y') construction, it may be very confusing. An alternative would be to have a bullet point list though it could make the paragraph vertically large. And fina alternative is to group those sentences:
The slice of *s* from *i* to *j* is defined as the sequence of items with index *k* such that ``i <= k < j``.
If *i* or *j* is greater than ``len(s)``, use ``len(s)``.
If *i* or *j* is less than ``-len(s)``, use ``0``.
If *i* is omitted or ``None``, use ``0``.
If *j* is omitted or ``None``, use ``len(s)``.
If *i* is greater than or equal to *j*, the slice is empty.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that "respectively" is confusing. And let's not compress further, dense text is harder to read and understand.
I like that final one, with bullets, and slightly re-ordered with simpler cases first:
The slice of *s* from *i* to *j* is defined as the sequence of items with index *k* such that ``i <= k < j``.
* If *i* is omitted or ``None``, use ``0``.
* If *j* is omitted or ``None``, use ``len(s)``.
* If *i* or *j* is less than ``-len(s)``, use ``0``.
* If *i* or *j* is greater than ``len(s)``, use ``len(s)``.
* If *i* is greater than or equal to *j*, the slice is empty.
This explain what happens when for negative start or stop arguments of big magnitude.
Also reference sequence term in the :mod:
arraydocs.sequence.insert#143420📚 Documentation preview 📚: https://cpython-previews--143422.org.readthedocs.build/en/143422/library/stdtypes.html