summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorDennis Sweeney <36520290+sweeneyde@users.noreply.github.com>2020-06-12 17:19:25 (GMT)
committerGitHub <noreply@github.com>2020-06-12 17:19:25 (GMT)
commit3ee0e48b0376a710c08eec6f30e4181563b192a2 (patch)
tree8a0ea5514e2b1bfb3617f434271c85465d805463 /Doc
parent0d3350daa8123a3e16d4a534b6e873eb12c10d7c (diff)
downloadcpython-3ee0e48b0376a710c08eec6f30e4181563b192a2.zip
cpython-3ee0e48b0376a710c08eec6f30e4181563b192a2.tar.gz
cpython-3ee0e48b0376a710c08eec6f30e4181563b192a2.tar.bz2
bpo-40890: Add `mapping` property to dict views (GH-20749)
Diffstat (limited to 'Doc')
-rw-r--r--Doc/library/stdtypes.rst12
-rw-r--r--Doc/whatsnew/3.10.rst5
2 files changed, 17 insertions, 0 deletions
diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst
index 2082b84..7028d24 100644
--- a/Doc/library/stdtypes.rst
+++ b/Doc/library/stdtypes.rst
@@ -4622,6 +4622,12 @@ support membership tests:
.. versionchanged:: 3.8
Dictionary views are now reversible.
+.. describe:: dictview.mapping
+
+ Return a :class:`types.MappingProxyType` that wraps the original
+ dictionary to which the view refers.
+
+ .. versionadded:: 3.10
Keys views are set-like since their entries are unique and hashable. If all
values are hashable, so that ``(key, value)`` pairs are unique and hashable,
@@ -4661,6 +4667,12 @@ An example of dictionary view usage::
>>> keys ^ {'sausage', 'juice'}
{'juice', 'sausage', 'bacon', 'spam'}
+ >>> # get back a read-only proxy for the original dictionary
+ >>> values.mapping
+ mappingproxy({'eggs': 2, 'sausage': 1, 'bacon': 1, 'spam': 500})
+ >>> values.mapping['spam']
+ 500
+
.. _typecontextmanager:
diff --git a/Doc/whatsnew/3.10.rst b/Doc/whatsnew/3.10.rst
index 1234b2e..629909b 100644
--- a/Doc/whatsnew/3.10.rst
+++ b/Doc/whatsnew/3.10.rst
@@ -74,6 +74,11 @@ New Features
number of ones in the binary expansion of a given integer, also known
as the population count. (Contributed by Niklas Fiekas in :issue:`29882`.)
+* The views returned by :meth:`dict.keys`, :meth:`dict.values` and
+ :meth:`dict.items` now all have a ``mapping`` attribute that gives a
+ :class:`types.MappingProxyType` object wrapping the original
+ dictionary. (Contributed by Dennis Sweeney in :issue:`40890`.)
+
Other Language Changes
======================