From 598ea16f922162e57f7db27d13943851617cfca0 Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Mon, 5 Jan 2026 05:12:02 +0300 Subject: [PATCH 1/4] gh-143420: Clarify sequence behavior for slice indexes This explain what happens when for negative start or stop arguments of big magnitude. Also reference sequence term in the :mod:`array` docs. --- Doc/library/array.rst | 2 +- Doc/library/stdtypes.rst | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Doc/library/array.rst b/Doc/library/array.rst index 1f04f697c7507f..e426dcc5f12728 100644 --- a/Doc/library/array.rst +++ b/Doc/library/array.rst @@ -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 :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 diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index 7eaa9f48ab5bc4..f2eed6590b4fd4 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -1095,7 +1095,8 @@ Notes: (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 + ``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. From f8737d8a90a774a55a05b5cadf639a1fc6e8c68b Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Tue, 6 Jan 2026 03:47:57 +0300 Subject: [PATCH 2/4] Add reference to "Mutable Sequence Types" in array description --- Doc/library/array.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/array.rst b/Doc/library/array.rst index e426dcc5f12728..14272630ce8c5b 100644 --- a/Doc/library/array.rst +++ b/Doc/library/array.rst @@ -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 ` :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, From 03732f999dd35a874c7af2f5a747be374e590a09 Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Sun, 11 Jan 2026 02:11:40 +0300 Subject: [PATCH 3/4] address review: sequence -> mutable sequence --- Doc/library/array.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/array.rst b/Doc/library/array.rst index 14272630ce8c5b..5592bd7089ba49 100644 --- a/Doc/library/array.rst +++ b/Doc/library/array.rst @@ -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 :term:`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 From 5eef361725570e7e6350a32452976684ac07ddd0 Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Sun, 11 Jan 2026 02:15:23 +0300 Subject: [PATCH 4/4] address review: reword note (4) --- Doc/library/stdtypes.rst | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index c610d01f569219..d03001f1cade05 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -1093,12 +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* 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. + 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