Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e6b2b78

Browse files
committed
Merge 3.4
2 parents 927131e + b67f6e2 commit e6b2b78

3 files changed

Lines changed: 18 additions & 5 deletions

File tree

Doc/library/stdtypes.rst

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3761,11 +3761,13 @@ pairs within braces, for example: ``{'jack': 4098, 'sjoerd': 4127}`` or ``{4098:
37613761
Return the item of *d* with key *key*. Raises a :exc:`KeyError` if *key* is
37623762
not in the map.
37633763

3764-
If a subclass of dict defines a method :meth:`__missing__`, if the key *key*
3764+
.. index:: __missing__()
3765+
3766+
If a subclass of dict defines a method :meth:`__missing__` and *key*
37653767
is not present, the ``d[key]`` operation calls that method with the key *key*
37663768
as argument. The ``d[key]`` operation then returns or raises whatever is
3767-
returned or raised by the ``__missing__(key)`` call if the key is not
3768-
present. No other operations or methods invoke :meth:`__missing__`. If
3769+
returned or raised by the ``__missing__(key)`` call.
3770+
No other operations or methods invoke :meth:`__missing__`. If
37693771
:meth:`__missing__` is not defined, :exc:`KeyError` is raised.
37703772
:meth:`__missing__` must be a method; it cannot be an instance variable::
37713773

@@ -3779,8 +3781,9 @@ pairs within braces, for example: ``{'jack': 4098, 'sjoerd': 4127}`` or ``{4098:
37793781
>>> c['red']
37803782
1
37813783

3782-
See :class:`collections.Counter` for a complete implementation including
3783-
other methods helpful for accumulating and managing tallies.
3784+
The example above shows part of the implementation of
3785+
:class:`collections.Counter`. A different ``__missing__`` method is used
3786+
by :class:`collections.defaultdict`.
37843787

37853788
.. describe:: d[key] = value
37863789

Doc/reference/datamodel.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1904,6 +1904,12 @@ through the container; for mappings, :meth:`__iter__` should be the same as
19041904
indexes to allow proper detection of the end of the sequence.
19051905

19061906

1907+
.. method:: object.__missing__(self, key)
1908+
1909+
Called by :class:`dict`\ .\ :meth:`__getitem__` to implement ``self[key]`` for dict subclasses
1910+
when key is not in the dictionary.
1911+
1912+
19071913
.. method:: object.__setitem__(self, key, value)
19081914

19091915
Called to implement assignment to ``self[key]``. Same note as for

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5676,6 +5676,10 @@ C-API
56765676
Documentation
56775677
-------------
56785678

5679+
- Issue #23006: Improve the documentation and indexing of dict.__missing__.
5680+
Add an entry in the language datamodel special methods section.
5681+
Revise and index its discussion in the stdtypes mapping/dict section.
5682+
56795683
- Issue #17701: Improving strftime documentation.
56805684

56815685
- Issue #18440: Clarify that `hash()` can truncate the value returned from an

0 commit comments

Comments
 (0)