diff options
author | Thomas Wouters <thomas@python.org> | 2000-08-17 22:37:32 (GMT) |
---|---|---|
committer | Thomas Wouters <thomas@python.org> | 2000-08-17 22:37:32 (GMT) |
commit | 1d75a79c009e500923128716a02efbe86135e64e (patch) | |
tree | 9c978062db6b1e9c4c775a9d4b763fd115bd671e /Doc/ref | |
parent | 68add2e9389e9cb2b74e448201ec101564391fe5 (diff) | |
download | cpython-1d75a79c009e500923128716a02efbe86135e64e.zip cpython-1d75a79c009e500923128716a02efbe86135e64e.tar.gz cpython-1d75a79c009e500923128716a02efbe86135e64e.tar.bz2 |
Apply SF patch #101029: call __getitem__ with a proper slice object if there
is no __getslice__ available. Also does the same for C extension types.
Includes rudimentary documentation (it could use a cross reference to the
section on slice objects, I couldn't figure out how to do that) and a test
suite for all Python __hooks__ I could think of, including the new
behaviour.
Diffstat (limited to 'Doc/ref')
-rw-r--r-- | Doc/ref/ref3.tex | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/Doc/ref/ref3.tex b/Doc/ref/ref3.tex index cdf5e62..98625a9 100644 --- a/Doc/ref/ref3.tex +++ b/Doc/ref/ref3.tex @@ -1042,11 +1042,12 @@ objects. The first set of methods is used either to emulate a sequence or to emulate a mapping; the difference is that for a sequence, the allowable keys should be the integers \var{k} for which \code{0 <= \var{k} < \var{N}} where \var{N} is the length of the -sequence, and the method \method{__getslice__()} (see below) should be -defined. It is also recommended that mappings provide methods -\method{keys()}, \method{values()}, \method{items()}, -\method{has_key()}, \method{get()}, \method{clear()}, \method{copy()}, -and \method{update()} behaving similar to those for +sequence, or slice objects, which define a range of items. (For backwards +compatibility, the method \method{__getslice__()} (see below) can also be +defined to handle simple, but not extended slices.) It is also recommended +that mappings provide methods \method{keys()}, \method{values()}, +\method{items()}, \method{has_key()}, \method{get()}, \method{clear()}, +\method{copy()}, and \method{update()} behaving similar to those for Python's standard dictionary objects; mutable sequences should provide methods \method{append()}, \method{count()}, \method{index()}, \method{insert()}, \method{pop()}, \method{remove()}, \method{reverse()} @@ -1141,22 +1142,30 @@ If the instance does not implement the \method{__len__()} method, an No guarantee is made that indexes adjusted this way are not still negative. Indexes which are greater than the length of the sequence are not modified. +This method is deprecated. If no \method{__getslice__()} is found, a slice +object is created instead, and passed to \method{__getitem__()} instead. \end{methoddesc} \begin{methoddesc}[sequence object]{__setslice__}{self, i, j, sequence} Called to implement assignment to \code{\var{self}[\var{i}:\var{j}]}. Same notes for \var{i} and \var{j} as for \method{__getslice__()}. + +This method is deprecated. If no \method{__setslice__()} is found, a slice +object is created instead, and passed to \method{__setitem__()} instead. \end{methoddesc} \begin{methoddesc}[sequence object]{__delslice__}{self, i, j} Called to implement deletion of \code{\var{self}[\var{i}:\var{j}]}. Same notes for \var{i} and \var{j} as for \method{__getslice__()}. +This method is deprecated. If no \method{__delslice__()} is found, a slice +object is created instead, and passed to \method{__delitem__()} instead. \end{methoddesc} -Notice that these methods are only invoked when a single slice with a -single colon is used. For slice operations involving extended slice -notation, \method{__getitem__()}, \method{__setitem__()} -or\method{__delitem__()} is called. +Notice that these methods are only invoked when a single slice with a single +colon is used, and the slice method is available. For slice operations +involving extended slice notation, or in absence of the slice methods, +\method{__getitem__()}, \method{__setitem__()} or \method{__delitem__()} is +called with a slice object as argument. \subsection{Emulating numeric types\label{numeric-types}} |