@@ -1091,24 +1091,34 @@ \subsection{Emulating sequence and mapping types\label{sequence-types}}
10911091
10921092\begin {methoddesc }[mapping object]{__getitem__}{self, key}
10931093Called to implement evaluation of \code {\var {self}[\var {key}]}.
1094- For a sequence types, the accepted keys should be integers. Note that the
1095- special interpretation of negative indices (if the class wishes to
1094+ For a sequence types, the accepted keys should be integers. Note that
1095+ the special interpretation of negative indices (if the class wishes to
10961096emulate a sequence type) is up to the \method {__getitem__()} method.
1097+ If \var {key} is of an inappropriate type, \exception {TypeError} may be
1098+ raised; if of a value outside the set of indexes for the sequence
1099+ (after any special interpretation of negative values),
1100+ \exception {IndexError} should be raised.
1101+ \strong {Note:} \keyword {for} loops expect that an
1102+ \exception {IndexError} will be raised for illegal indexes to allow
1103+ proper detection of the end of the sequence.
10971104\end {methoddesc }
10981105
10991106\begin {methoddesc }[mapping object]{__setitem__}{self, key, value}
11001107Called to implement assignment to \code {\var {self}[\var {key}]}. Same
11011108note as for \method {__getitem__()}. This should only be implemented
11021109for mappings if the objects support changes to the values for keys, or
11031110if new keys can be added, or for sequences if elements can be
1104- replaced.
1111+ replaced. The same exceptions should be raised for improper
1112+ \var {key} values as for the \method {__getitem__()} method.
11051113\end {methoddesc }
11061114
11071115\begin {methoddesc }[mapping object]{__delitem__}{self, key}
11081116Called to implement deletion of \code {\var {self}[\var {key}]}. Same
11091117note as for \method {__getitem__()}. This should only be implemented
11101118for mappings if the objects support removal of keys, or for sequences
1111- if elements can be removed from the sequence.
1119+ if elements can be removed from the sequence. The same exceptions
1120+ should be raised for improper \var {key} values as for the
1121+ \method {__getitem__()} method.
11121122\end {methoddesc }
11131123
11141124
0 commit comments