https://github.com/python/cpython/commit/21764ec5ab2dd9a97fe1ff8613dcddb35ef4b11a
commit: 21764ec5ab2dd9a97fe1ff8613dcddb35ef4b11a
branch: 3.13
author: Miss Islington (bot) <[email protected]>
committer: AlexWaygood <[email protected]>
date: 2024-10-11T23:29:01Z
summary:

[3.13] gh-116938: Clarify documentation of `dict` and `dict.update` regarding 
the positional argument they accept (GH-125213) (#125336)

Co-authored-by: Victorien <[email protected]>
Co-authored-by: Alex Waygood <[email protected]>

files:
M Doc/library/stdtypes.rst
M Lib/_collections_abc.py

diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst
index 8b9d29545e328b..c77399461edc38 100644
--- a/Doc/library/stdtypes.rst
+++ b/Doc/library/stdtypes.rst
@@ -4469,14 +4469,14 @@ can be used interchangeably to index the same 
dictionary entry.
      ``dict([('foo', 100), ('bar', 200)])``, ``dict(foo=100, bar=200)``
 
    If no positional argument is given, an empty dictionary is created.
-   If a positional argument is given and it is a mapping object, a dictionary
-   is created with the same key-value pairs as the mapping object.  Otherwise,
-   the positional argument must be an :term:`iterable` object.  Each item in
-   the iterable must itself be an iterable with exactly two objects.  The
-   first object of each item becomes a key in the new dictionary, and the
-   second object the corresponding value.  If a key occurs more than once, the
-   last value for that key becomes the corresponding value in the new
-   dictionary.
+   If a positional argument is given and it defines a ``keys()`` method, a
+   dictionary is created by calling :meth:`~object.__getitem__` on the 
argument with
+   each returned key from the method.  Otherwise, the positional argument must 
be an
+   :term:`iterable` object.  Each item in the iterable must itself be an 
iterable
+   with exactly two elements.  The first element of each item becomes a key in 
the
+   new dictionary, and the second element the corresponding value.  If a key 
occurs
+   more than once, the last value for that key becomes the corresponding value 
in
+   the new dictionary.
 
    If keyword arguments are given, the keyword arguments and their values are
    added to the dictionary created from the positional argument.  If a key
@@ -4633,10 +4633,11 @@ can be used interchangeably to index the same 
dictionary entry.
       Update the dictionary with the key/value pairs from *other*, overwriting
       existing keys.  Return ``None``.
 
-      :meth:`update` accepts either another dictionary object or an iterable of
-      key/value pairs (as tuples or other iterables of length two).  If keyword
-      arguments are specified, the dictionary is then updated with those
-      key/value pairs: ``d.update(red=1, blue=2)``.
+      :meth:`update` accepts either another object with a ``keys()`` method (in
+      which case :meth:`~object.__getitem__` is called with every key returned 
from
+      the method). or an iterable of key/value pairs (as tuples or other 
iterables
+      of length two). If keyword arguments are specified, the dictionary is 
then
+      updated with those key/value pairs: ``d.update(red=1, blue=2)``.
 
    .. method:: values()
 
diff --git a/Lib/_collections_abc.py b/Lib/_collections_abc.py
index 036254869d52c3..aebe9c8b64ac08 100644
--- a/Lib/_collections_abc.py
+++ b/Lib/_collections_abc.py
@@ -978,7 +978,7 @@ def clear(self):
 
     def update(self, other=(), /, **kwds):
         ''' D.update([E, ]**F) -> None.  Update D from mapping/iterable E and 
F.
-            If E present and has a .keys() method, does:     for k in E: D[k] 
= E[k]
+            If E present and has a .keys() method, does:     for k in 
E.keys(): D[k] = E[k]
             If E present and lacks .keys() method, does:     for (k, v) in E: 
D[k] = v
             In either case, this is followed by: for k, v in F.items(): D[k] = 
v
         '''

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to