Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
e6b2b78a
Commit
e6b2b78a
authored
Dec 10, 2014
by
Terry Jan Reedy
Browse files
Options
Browse Files
Download
Plain Diff
Merge 3.4
parents
927131e0
b67f6e27
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
5 deletions
+18
-5
Doc/library/stdtypes.rst
Doc/library/stdtypes.rst
+8
-5
Doc/reference/datamodel.rst
Doc/reference/datamodel.rst
+6
-0
Misc/NEWS
Misc/NEWS
+4
-0
No files found.
Doc/library/stdtypes.rst
View file @
e6b2b78a
...
...
@@ -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
...
...
Doc/reference/datamodel.rst
View file @
e6b2b78a
...
...
@@ -1904,6 +1904,12 @@ through the container; for mappings, :meth:`__iter__` should be the same as
indexes to allow proper detection of the end of the sequence.
.. method:: object.__missing__(self, key)
Called by :class:`dict`\ .\ :meth:`__getitem__` to implement ``self[key]`` for dict subclasses
when key is not in the dictionary.
.. method:: object.__setitem__(self, key, value)
Called to implement assignment to ``self[key]``. Same note as for
...
...
Misc/NEWS
View file @
e6b2b78a
...
...
@@ -5676,6 +5676,10 @@ C-API
Documentation
-------------
-
Issue
#
23006
:
Improve
the
documentation
and
indexing
of
dict
.
__missing__
.
Add
an
entry
in
the
language
datamodel
special
methods
section
.
Revise
and
index
its
discussion
in
the
stdtypes
mapping
/
dict
section
.
-
Issue
#
17701
:
Improving
strftime
documentation
.
-
Issue
#
18440
:
Clarify
that
`
hash
()`
can
truncate
the
value
returned
from
an
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment