Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1dc5a84

Browse files
committed
Bug #801349: document that start/stop/step slice arguments can be None
1 parent b2699b2 commit 1dc5a84

2 files changed

Lines changed: 7 additions & 6 deletions

File tree

Doc/lib/libstdtypes.tex

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -532,9 +532,10 @@ \subsection{Sequence Types ---
532532
\item[(4)] The slice of \var{s} from \var{i} to \var{j} is defined as
533533
the sequence of items with index \var{k} such that \code{\var{i} <=
534534
\var{k} < \var{j}}. If \var{i} or \var{j} is greater than
535-
\code{len(\var{s})}, use \code{len(\var{s})}. If \var{i} is omitted,
536-
use \code{0}. If \var{j} is omitted, use \code{len(\var{s})}. If
537-
\var{i} is greater than or equal to \var{j}, the slice is empty.
535+
\code{len(\var{s})}, use \code{len(\var{s})}. If \var{i} is omitted
536+
or \code{None}, use \code{0}. If \var{j} is omitted or \code{None},
537+
use \code{len(\var{s})}. If \var{i} is greater than or equal to \var{j},
538+
the slice is empty.
538539

539540
\item[(5)] The slice of \var{s} from \var{i} to \var{j} with step
540541
\var{k} is defined as the sequence of items with index
@@ -543,9 +544,9 @@ \subsection{Sequence Types ---
543544
are \code{i}, \code{i+k}, \code{i+2*k}, \code{i+3*k} and so on, stopping when
544545
\var{j} is reached (but never including \var{j}). If \var{i} or \var{j}
545546
is greater than \code{len(\var{s})}, use \code{len(\var{s})}. If
546-
\var{i} or \var{j} are omitted then they become ``end'' values
547+
\var{i} or \var{j} are omitted or \code{None}, they become ``end'' values
547548
(which end depends on the sign of \var{k}). Note, \var{k} cannot
548-
be zero.
549+
be zero. If \var{k} is \code{None}, it is treated like \code{1}.
549550

550551
\item[(6)] If \var{s} and \var{t} are both strings, some Python
551552
implementations such as CPython can usually perform an in-place optimization

Python/ceval.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3905,7 +3905,7 @@ _PyEval_SliceIndex(PyObject *v, Py_ssize_t *pi)
39053905
}
39063906
} else {
39073907
PyErr_SetString(PyExc_TypeError,
3908-
"slice indices must be integers");
3908+
"slice indices must be integers or None");
39093909
return 0;
39103910
}
39113911
*pi = x;

0 commit comments

Comments
 (0)