diff options
author | Terry Jan Reedy <tjreedy@udel.edu> | 2014-12-10 23:39:45 (GMT) |
---|---|---|
committer | Terry Jan Reedy <tjreedy@udel.edu> | 2014-12-10 23:39:45 (GMT) |
commit | e6b2b78a7d2715e5b645825924c575ceff3d4205 (patch) | |
tree | 98ff251874393ff38cea4ba0123fd2cbbce091a4 /Doc/library/stdtypes.rst | |
parent | 927131e050950e7345b2f3e19e8a57c2a328385b (diff) | |
parent | b67f6e27e11264876e185cacd8ebabbf41c27fb0 (diff) | |
download | cpython-e6b2b78a7d2715e5b645825924c575ceff3d4205.zip cpython-e6b2b78a7d2715e5b645825924c575ceff3d4205.tar.gz cpython-e6b2b78a7d2715e5b645825924c575ceff3d4205.tar.bz2 |
Merge 3.4
Diffstat (limited to 'Doc/library/stdtypes.rst')
-rw-r--r-- | Doc/library/stdtypes.rst | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index 57fd0b1..ff06e85 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -3761,11 +3761,13 @@ pairs within braces, for example: ``{'jack': 4098, 'sjoerd': 4127}`` or ``{4098: Return the item of *d* with key *key*. Raises a :exc:`KeyError` if *key* is not in the map. - If a subclass of dict defines a method :meth:`__missing__`, if the key *key* + .. index:: __missing__() + + If a subclass of dict defines a method :meth:`__missing__` and *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 - returned or raised by the ``__missing__(key)`` call if the key is not - present. No other operations or methods invoke :meth:`__missing__`. If + returned or raised by the ``__missing__(key)`` call. + No other operations or methods invoke :meth:`__missing__`. If :meth:`__missing__` is not defined, :exc:`KeyError` is raised. :meth:`__missing__` must be a method; it cannot be an instance variable:: @@ -3779,8 +3781,9 @@ pairs within braces, for example: ``{'jack': 4098, 'sjoerd': 4127}`` or ``{4098: >>> 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 |