Mercurial > cpython-lru_cache-weakref
diff Doc/lib/libstdtypes.tex @ 36656:92ce8bb8b12a legacy-trunk
- Patch 1433928:
- The copy module now "copies" function objects (as atomic objects).
- dict.__getitem__ now looks for a __missing__ hook before raising
KeyError.
- Added a new type, defaultdict, to the collections module.
This uses the new __missing__ hook behavior added to dict (see above).
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Sat, 25 Feb 2006 22:38:04 +0000 |
| parents | 8e13236243dd |
| children | 64c83e0f683e 9ef3fac5d2c0 |
line wrap: on
line diff
--- a/Doc/lib/libstdtypes.tex Sat Feb 25 15:43:10 2006 +0000 +++ b/Doc/lib/libstdtypes.tex Sat Feb 25 22:38:04 2006 +0000 @@ -1350,7 +1350,7 @@ \begin{tableiii}{c|l|c}{code}{Operation}{Result}{Notes} \lineiii{len(\var{a})}{the number of items in \var{a}}{} - \lineiii{\var{a}[\var{k}]}{the item of \var{a} with key \var{k}}{(1)} + \lineiii{\var{a}[\var{k}]}{the item of \var{a} with key \var{k}}{(1), (10)} \lineiii{\var{a}[\var{k}] = \var{v}} {set \code{\var{a}[\var{k}]} to \var{v}} {} @@ -1454,6 +1454,17 @@ \versionchanged[Allowed the argument to be an iterable of key/value pairs and allowed keyword arguments]{2.4} +\item[(10)] If a subclass of dict defines a method \method{__missing__}, +if the key \var{k} is not present, the \var{a}[\var{k}] operation calls +that method with the key \var{k} as argument. The \var{a}[\var{k}] +operation then returns or raises whatever is returned or raised by the +\function{__missing__}(\var{k}) call if the key is not present. +No other operations or methods invoke \method{__missing__}(). +If \method{__missing__} is not defined, \exception{KeyError} is raised. +\method{__missing__} must be a method; it cannot be an instance variable. +For an example, see \module{collections}.\class{defaultdict}. +\versionadded{2.5} + \end{description} \subsection{File Objects
