]> granicus.if.org Git - python/commitdiff
Merged revisions 82821 via svnmerge from
authorMark Dickinson <dickinsm@gmail.com>
Sun, 11 Jul 2010 19:17:28 +0000 (19:17 +0000)
committerMark Dickinson <dickinsm@gmail.com>
Sun, 11 Jul 2010 19:17:28 +0000 (19:17 +0000)
svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r82821 | mark.dickinson | 2010-07-11 19:53:06 +0100 (Sun, 11 Jul 2010) | 3 lines

  Issue #9137: Fix issue in MutableMapping.update, which incorrectly
  treated keyword arguments called 'self' or 'other' specially.
........

Lib/_abcoll.py
Lib/test/test_collections.py
Misc/NEWS

index ad5a9c0758da619b4b5b04166d63cfbfc35837c1..a442d7c8a74bbc47f90f1762268d2d8fdfe0b1d2 100644 (file)
@@ -466,7 +466,15 @@ class MutableMapping(Mapping):
         except KeyError:
             pass
 
-    def update(self, other=(), **kwds):
+    def update(*args, **kwds):
+        if len(args) > 2:
+            raise TypeError("update() takes at most 2 positional "
+                            "arguments ({} given)".format(len(args)))
+        elif not args:
+            raise TypeError("update() takes at least 1 argument (0 given)")
+        self = args[0]
+        other = args[1] if len(args) >= 2 else ()
+
         if isinstance(other, Mapping):
             for key in other:
                 self[key] = other[key]
index 363511f62ba326e063a0add059d7633a6dc848b9..a0f0fbc5563a0d3e186b02da217a83266be9355d 100644 (file)
@@ -766,6 +766,19 @@ class TestOrderedDict(unittest.TestCase):
         od.update([('a', 1), ('b', 2), ('c', 9), ('d', 4)], c=3, e=5)
         self.assertEqual(list(od.items()), pairs)                                   # mixed input
 
+        # Issue 9137: Named argument called 'other' or 'self'
+        # shouldn't be treated specially.
+        od = OrderedDict()
+        od.update(self=23)
+        self.assertEqual(list(od.items()), [('self', 23)])
+        od = OrderedDict()
+        od.update(other={})
+        self.assertEqual(list(od.items()), [('other', {})])
+        od = OrderedDict()
+        od.update(red=5, blue=6, other=7, self=8)
+        self.assertEqual(sorted(list(od.items())),
+                         [('blue', 6), ('other', 7), ('red', 5), ('self', 8)])
+
         # Make sure that direct calls to update do not clear previous contents
         # add that updates items are not moved to the end
         d = OrderedDict([('a', 1), ('b', 2), ('c', 3), ('d', 44), ('e', 55)])
index 81e1b5b5a8a1e417ee0d7caf4a53f4dcdac124e6..bc48622e21d3b87ded4aa94075987745b73da4ae 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -1005,6 +1005,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #9137: Fix issue in MutableMapping.update, which incorrectly
+  treated keyword arguments called 'self' or 'other' specially.
+
 - Issue #7835: shelve should no longer produce mysterious warnings during
   interpreter shutdown.