classification
Title: dict.update.__doc__ is misleading
Type: Stage:
Components: Interpreter Core Versions: Python 3.2, Python 3.1, Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: eric.araujo, ivank, r.david.murray, rhettinger
Priority: normal Keywords: patch

Created on 2010-10-30 02:34 by ivank, last changed 2010-11-02 19:02 by eric.araujo.

Files
File name Uploaded Description Edit
dict.update.__doc__.patch ivank, 2010-10-30 02:34 mention fast path and .keys()
Messages (4)
msg119954 - (view) Author: ivank (ivank) Date: 2010-10-30 02:34
It would be nice if dict.update.__doc__ conveyed some of the subtleties of the update algorithm.  See the patch.  I changed __doc__ to mention the fast path for dicts, and changed one instance of E: -> E.keys():
msg119961 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2010-10-30 06:07
I'm not sure that we should mention the fast path for dicts.  That is an implementation detail and may not be present in IronPython, PyPy, Jython, etc.

The current version includes:

  D.updated(E, **F) --> None.  Updated D for dict/iterable E and F.

ISTM that covers the semantics of what it does.  Your proposed modification gets into how it does it.
msg119962 - (view) Author: ivank (ivank) Date: 2010-10-30 06:32
CPython's dict(obj) ignores `keys` and `__iter__` if obj is a subclass of dict.  I thought this was an important language detail, not just an implementation quirk.  But, I just tested pypy 1.3, and it is calling .keys() on dicts.  Oh well.

I think the __doc__ can still be slightly improved; ignore my patch and just change the first E: to E.keys(): - that would be more accurate.
msg119978 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-10-30 12:59
Maybe the fastpath should do a strict check and not be used for subclasses of dict?
History
Date User Action Args
2010-11-02 19:02:18eric.araujosetnosy: + eric.araujo

versions: - Python 2.6, Python 2.5, Python 3.3
2010-10-30 12:59:48r.david.murraysetnosy: + r.david.murray
messages: + msg119978
2010-10-30 06:32:32ivanksetmessages: + msg119962
2010-10-30 06:07:24rhettingersetnosy: + rhettinger
messages: + msg119961
2010-10-30 02:34:06ivankcreate