Make sets and deques weak referencable.

This commit is contained in:
Raymond Hettinger 2004-05-30 07:26:47 +00:00
parent d70ad8a9d9
commit 691d80532b
5 changed files with 32 additions and 6 deletions

View file

@ -1,6 +1,7 @@
from collections import deque
import unittest
from test import test_support
from weakref import proxy
import copy
import cPickle as pickle
from cStringIO import StringIO
@ -435,6 +436,12 @@ class TestSubclass(unittest.TestCase):
self.assertEqual(type(d), type(e))
self.assertEqual(list(d), list(e))
def test_weakref(self):
d = deque('gallahad')
p = proxy(d)
self.assertEqual(str(p), str(d))
d = None
self.assertRaises(ReferenceError, str, p)
#==============================================================================

View file

@ -1,5 +1,6 @@
import unittest
from test import test_support
from weakref import proxy
import operator
import copy
import pickle
@ -346,6 +347,13 @@ class TestSet(TestJointOps):
else:
self.assert_(c not in self.s)
def test_weakref(self):
s = self.thetype('gallahad')
p = proxy(s)
self.assertEqual(str(p), str(s))
s = None
self.assertRaises(ReferenceError, str, p)
class SetSubclass(set):
pass