Skip to content

Commit cf5b31c

Browse files
[3.13] gh-143420: Clarify sequence behavior for slice indexes (GH-143422) (#143703)
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
1 parent 0dc3c08 commit cf5b31c

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

Doc/library/array.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
--------------
1010

1111
This module defines an object type which can compactly represent an array of
12-
basic values: characters, integers, floating-point numbers. Arrays are sequence
12+
basic values: characters, integers, floating-point numbers. Arrays are mutable :term:`sequence`
1313
types and behave very much like lists, except that the type of objects stored in
1414
them is constrained. The type is specified at object creation time by using a
1515
:dfn:`type code`, which is a single character. The following type codes are
@@ -93,7 +93,7 @@ The module defines the following type:
9393
otherwise, the initializer's iterator is passed to the :meth:`extend` method
9494
to add initial items to the array.
9595

96-
Array objects support the ordinary sequence operations of indexing, slicing,
96+
Array objects support the ordinary :ref:`mutable <typesseq-mutable>` :term:`sequence` operations of indexing, slicing,
9797
concatenation, and multiplication. When using slice assignment, the assigned
9898
value must be an array object with the same type code; in all other cases,
9999
:exc:`TypeError` is raised. Array objects also implement the buffer interface,

Doc/library/stdtypes.rst

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,11 +1049,14 @@ Notes:
10491049
still ``0``.
10501050

10511051
(4)
1052-
The slice of *s* from *i* to *j* is defined as the sequence of items with index
1053-
*k* such that ``i <= k < j``. If *i* or *j* is greater than ``len(s)``, use
1054-
``len(s)``. If *i* is omitted or ``None``, use ``0``. If *j* is omitted or
1055-
``None``, use ``len(s)``. If *i* is greater than or equal to *j*, the slice is
1056-
empty.
1052+
The slice of *s* from *i* to *j* is defined as the sequence of items with
1053+
index *k* such that ``i <= k < j``.
1054+
1055+
* If *i* is omitted or ``None``, use ``0``.
1056+
* If *j* is omitted or ``None``, use ``len(s)``.
1057+
* If *i* or *j* is less than ``-len(s)``, use ``0``.
1058+
* If *i* or *j* is greater than ``len(s)``, use ``len(s)``.
1059+
* If *i* is greater than or equal to *j*, the slice is empty.
10571060

10581061
(5)
10591062
The slice of *s* from *i* to *j* with step *k* is defined as the sequence of

0 commit comments

Comments
 (0)