mirror of
https://github.com/python/cpython.git
synced 2025-08-03 08:34:29 +00:00
Make sets and deques weak referencable.
This commit is contained in:
parent
d70ad8a9d9
commit
691d80532b
5 changed files with 32 additions and 6 deletions
|
@ -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)
|
||||
|
||||
#==============================================================================
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue