]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.14] gh-143420: Clarify sequence behavior for slice indexes (GH-143422) (#143701)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sun, 11 Jan 2026 17:23:51 +0000 (18:23 +0100)
committerGitHub <noreply@github.com>
Sun, 11 Jan 2026 17:23:51 +0000 (17:23 +0000)
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
Doc/library/array.rst
Doc/library/stdtypes.rst

index 1f04f697c7507f5995a4aee85d92943715bf46ff..5592bd7089ba49335fd97ef0fb983097dda64d50 100644 (file)
@@ -9,7 +9,7 @@
 --------------
 
 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 mutable :term:`sequence`
 types and behave very much like lists, except that the type of objects stored in
 them is constrained.  The type is specified at object creation time by using a
 :dfn:`type code`, which is a single character.  The following type codes are
@@ -93,7 +93,7 @@ The module defines the following type:
    otherwise, the initializer's iterator is passed to the :meth:`extend` method
    to add initial items to the array.
 
-   Array objects support the ordinary sequence operations of indexing, slicing,
+   Array objects support the ordinary :ref:`mutable <typesseq-mutable>` :term:`sequence` operations of indexing, slicing,
    concatenation, and multiplication.  When using slice assignment, the assigned
    value must be an array object with the same type code; in all other cases,
    :exc:`TypeError` is raised. Array objects also implement the buffer interface,
index 7663c15cc1a79909108d459ef2961fd6680271cc..f250f9fd6ece5890563ccbbd95f94a96677cfec5 100644 (file)
@@ -1093,11 +1093,14 @@ Notes:
    still ``0``.
 
 (4)
-   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* 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.
+   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.
 
 (5)
    The slice of *s* from *i* to *j* with step *k* is defined as the sequence of