Issue #22958: Constructor and update method of weakref.WeakValueDictionary
now accept the self keyword argument.
diff --git a/Lib/test/test_weakref.py b/Lib/test/test_weakref.py
index cc0a755..b7f985c 100644
--- a/Lib/test/test_weakref.py
+++ b/Lib/test/test_weakref.py
@@ -1197,6 +1197,18 @@
dict[o] = o.arg
return dict, objects
+ def test_make_weak_valued_dict_misc(self):
+ # errors
+ self.assertRaises(TypeError, weakref.WeakValueDictionary.__init__)
+ self.assertRaises(TypeError, weakref.WeakValueDictionary, {}, {})
+ self.assertRaises(TypeError, weakref.WeakValueDictionary, (), ())
+ # special keyword arguments
+ o = Object(3)
+ for kw in 'self', 'other', 'iterable':
+ d = weakref.WeakValueDictionary(**{kw: o})
+ self.assertEqual(list(d.keys()), [kw])
+ self.assertEqual(d[kw], o)
+
def make_weak_valued_dict(self):
dict = weakref.WeakValueDictionary()
objects = map(Object, range(self.COUNT))
@@ -1279,6 +1291,19 @@
def test_weak_valued_dict_update(self):
self.check_update(weakref.WeakValueDictionary,
{1: C(), 'a': C(), C(): C()})
+ # errors
+ self.assertRaises(TypeError, weakref.WeakValueDictionary.update)
+ d = weakref.WeakValueDictionary()
+ self.assertRaises(TypeError, d.update, {}, {})
+ self.assertRaises(TypeError, d.update, (), ())
+ self.assertEqual(list(d.keys()), [])
+ # special keyword arguments
+ o = Object(3)
+ for kw in 'self', 'dict', 'other', 'iterable':
+ d = weakref.WeakValueDictionary()
+ d.update(**{kw: o})
+ self.assertEqual(list(d.keys()), [kw])
+ self.assertEqual(d[kw], o)
def test_weak_keyed_dict_update(self):
self.check_update(weakref.WeakKeyDictionary,