Dict.update documentation bug

Gerrat Rickert grickert at coldstorage.com
Fri Dec 9 17:27:49 CET 2011


The current docstring for dict.update shows:

========================================================================
====
>>> help(dict.update)
Help on method_descriptor:

update(...)
    D.update(E, **F) -> None.  Update D from dict/iterable E and F.
    If E has a .keys() method, does:     for k in E: D[k] = E[k]
    If E lacks .keys() method, does:     for (k, v) in E: D[k] = v
    In either case, this is followed by: for k in F: D[k] = F[k]

>>>
========================================================================
====

Better, would be something like:

========================================================================
====
update(...)
    D.update(E=None, **F) -> None.  Update D from dict/iterable E and F.
    If E is not None then:
        If E has a .keys() method, does:     for k in E: D[k] = E[k]
        If E lacks .keys() method, does:     for (k, v) in E: D[k] = v

    In either case, this is followed by: for k in F: D[k] = F[k]
========================================================================
====

The current signature states that argument "E" is mandatory, when it is
not.

eg.
>>> d = {}
>>> d.update(mykey={1:2})  # just keywords passed in, no "E"
>>>


I tried subclassing the builtin dict using the current signature as a
guide, 
but my implementation was incorrect since I had assumed there was a
mandatory 
argument, "E".


Regards,
	Gerrat




More information about the Python-bugs-list mailing list