classification
Title: x.update(red=5, blue=6, other=7) doesn't work, where x is a MutableMapping
Type: behavior Stage: resolved
Components: Versions: Python 3.2
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: mark.dickinson Nosy List: amaury.forgeotdarc, belopolsky, mark.dickinson, rhettinger, stutzbach
Priority: normal Keywords: patch

Created on 2010-07-01 15:12 by stutzbach, last changed 2010-07-11 19:28 by mark.dickinson. This issue is now closed.

Files
File name Uploaded Description Edit
issue9137.patch mark.dickinson, 2010-07-02 09:35
issue9137_v2.patch mark.dickinson, 2010-07-02 10:04
Messages (7)
msg109055 - (view) Author: Daniel Stutzbach (stutzbach) (Python committer) Date: 2010-07-01 15:12
Simple example, using collections.OrderedDict:

>>> import collections
>>> x = collections.OrderedDict()
>>> x.update(red=5, blue=6, other=7)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/bin/../stow/Python-3.1.1/lib/python3.1/_abcoll.py", line 490, in update
    for key, value in other:
TypeError: 'int' object is not iterable

In MutableMapping.update, the first argument needs to be a positional-only argument.  Otherwise, it's impossible to use "other" as keyword argument to designate a key-value pair.
msg109092 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-07-02 09:35
Here's a fix.
msg109093 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2010-07-02 09:45
And what about this?
>>> x.update(self=5)
msg109094 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-07-02 09:48
Ah.  Good point.
msg109095 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-07-02 10:04
Updated patch, to deal with 'self' correctly too.
msg109188 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2010-07-03 18:17
Just a nitpick: I think the code will be clearer if you switch on args' length rather than catch IndexError:


nargs = len(args)
if nargs > 2:
   ...

self = args[0]
other = args[1] if nargs == 2 else ()
...
msg110036 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-07-11 19:28
Fixed in r82821 (py3k), r82823 (release27-maint) and r82824 (release31-maint).
History
Date User Action Args
2010-07-11 19:28:47mark.dickinsonsetstatus: open -> closed

messages: + msg110036
stage: patch review -> resolved
2010-07-03 18:17:52belopolskysetnosy: + belopolsky
messages: + msg109188
2010-07-02 18:09:41rhettingersetassignee: stutzbach -> mark.dickinson
resolution: accepted
2010-07-02 10:05:00mark.dickinsonsetfiles: + issue9137_v2.patch

messages: + msg109095
stage: needs patch -> patch review
2010-07-02 09:48:01mark.dickinsonsetmessages: + msg109094
2010-07-02 09:45:19amaury.forgeotdarcsetnosy: + amaury.forgeotdarc
messages: + msg109093
2010-07-02 09:35:27mark.dickinsonsetfiles: + issue9137.patch

nosy: + rhettinger
messages: + msg109092

keywords: + patch
2010-07-02 08:52:59mark.dickinsonsetnosy: + mark.dickinson
2010-07-01 15:12:40stutzbachcreate