Merged revisions 82821 via svnmerge from

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.
........
This commit is contained in:
Mark Dickinson 2010-07-11 19:27:06 +00:00
parent dedbbe6b3b
commit 16d037653d
3 changed files with 25 additions and 1 deletions

View File

@ -480,7 +480,15 @@ class MutableMapping(Mapping):
except KeyError: except KeyError:
pass 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): if isinstance(other, Mapping):
for key in other: for key in other:
self[key] = other[key] self[key] = other[key]

View File

@ -725,6 +725,19 @@ class TestOrderedDict(unittest.TestCase):
od.update([('a', 1), ('b', 2), ('c', 9), ('d', 4)], c=3, e=5) od.update([('a', 1), ('b', 2), ('c', 9), ('d', 4)], c=3, e=5)
self.assertEqual(list(od.items()), pairs) # mixed input 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 # Make sure that direct calls to update do not clear previous contents
# add that updates items are not moved to the end # add that updates items are not moved to the end
d = OrderedDict([('a', 1), ('b', 2), ('c', 3), ('d', 44), ('e', 55)]) d = OrderedDict([('a', 1), ('b', 2), ('c', 3), ('d', 44), ('e', 55)])

View File

@ -78,6 +78,9 @@ C-API
Library Library
------- -------
- Issue #9137: Fix issue in MutableMapping.update, which incorrectly
treated keyword arguments called 'self' or 'other' specially.
- Issue #7646: The fnmatch pattern cache no longer grows without bound. - Issue #7646: The fnmatch pattern cache no longer grows without bound.
- Issue #9136: Fix 'dictionary changed size during iteration' - Issue #9136: Fix 'dictionary changed size during iteration'