diff -r d5e15f5067c9 Doc/library/stdtypes.rst --- a/Doc/library/stdtypes.rst Sun Dec 07 13:46:02 2014 -0500 +++ b/Doc/library/stdtypes.rst Sun Dec 07 17:06:27 2014 -0500 @@ -3761,6 +3761,8 @@ Return the item of *d* with key *key*. Raises a :exc:`KeyError` if *key* is not in the map. + .. index:: __missing__() + If a subclass of dict defines a method :meth:`__missing__`, if the key *key* is not present, the ``d[key]`` operation calls that method with the key *key* as argument. The ``d[key]`` operation then returns or raises whatever is @@ -3779,8 +3781,9 @@ >>> c['red'] 1 - See :class:`collections.Counter` for a complete implementation including - other methods helpful for accumulating and managing tallies. + The example above shows part of the implementation of + :class:`collections.Counter`. A different ``__missing__`` method is used + by :class:`collections.defaultdict`. .. describe:: d[key] = value diff -r d5e15f5067c9 Doc/reference/datamodel.rst --- a/Doc/reference/datamodel.rst Sun Dec 07 13:46:02 2014 -0500 +++ b/Doc/reference/datamodel.rst Sun Dec 07 17:06:27 2014 -0500 @@ -1904,6 +1904,12 @@ indexes to allow proper detection of the end of the sequence. +.. method:: object.__missing__(self, key) + + Called by dict.__getitem__ to implement ``self[key]`` for dict subclasses + when key is not in the subdict. + + .. method:: object.__setitem__(self, key, value) Called to implement assignment to ``self[key]``. Same note as for