mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Patch #403985: Add support for weak-keyed dictionaries
This commit is contained in:
parent
bb40dc4892
commit
5e1633365d
5 changed files with 158 additions and 21 deletions
|
@ -152,6 +152,24 @@ for o in objects:
|
|||
dict.clear()
|
||||
print "weak dict test complete"
|
||||
|
||||
print
|
||||
print "Weak Keyed Dictionaries"
|
||||
|
||||
dict = weakref.mapping(weakkeys=1)
|
||||
objects = map(Object, range(10))
|
||||
for o in objects:
|
||||
dict[o] = o.arg
|
||||
print "objects are stored in weak dict"
|
||||
for o in objects:
|
||||
verify(weakref.getweakrefcount(o) == 1,
|
||||
"wrong number of weak references to %r!" % o)
|
||||
verify(o.arg is dict[o],
|
||||
"wrong object returned by weak dict!")
|
||||
del objects,o
|
||||
verify(len(dict)==0, "deleting the keys did not clear the dictionary")
|
||||
print "weak key dict test complete"
|
||||
|
||||
|
||||
print
|
||||
print "Non-callable Proxy References"
|
||||
print "XXX -- tests not written!"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue